Retrieve all mobile devices Google Directory API in .NET Application - c#

I want to Manage Device using Google API in my appilcation.How to retrieve all mobile/chrome OS device ?
CODE :
var listReq1 = service.Mobiledevices.List(serviceAccountEmail);
MobileDevices allUsers = listReq1.Execute();
Here,
serviceAccountEmail = "Service accounts Key" (Console.developer.google.com)
I am getting error like
Google.Apis.Requests.RequestError
Bad Request [400]
I tried using
var listReq= new Google.Apis.Admin.Directory.directory_v1.MobiledevicesResource.ListRequest(service,serviceAccountEmail);
Still not working ? I want all details of User just like Below Image

If you check the documentation for Mobiledevices: list
Retrieves a paginated list of all mobile devices for an account.
I will see that it takes a customer id as a parmater.
customerId The unique ID for the customer's Google account. As
an account administrator, you can also use the my_customer alias to
represent your account's customerId. The customerId is also returned
as part of the Users resource.
var listReq1 = service.Mobiledevices.List(customerId);
MobileDevices allUsers = listReq1.Execute();
You are sending service account email address which I really don't think is your customer id.

Related

Selecting a user by ID doesn't work, but works by email

I am using the Microsoft Graph API to access some events in my company's Azure AD Outlook.
The problem I am now having is that I can not access the CalendarView (or really I can't access the user at all) when I try to specify the user with an UUID instead of an email. The strange thing is that email works just fine, but I am not allowed to store emails outside of the Azure AD, so ID would be the preferred method.
Here is the exact API call I try to make: https://learn.microsoft.com/en-us/graph/api/user-list-calendarview?view=graph-rest-1.0&tabs=csharp
But all examples only use the .Me accessor and not the .Users[{ID | userPrincipalName}]
I am quite sure that the UUID I use is correct since it comes from an API call earlier. Or does the documentation article mean something else than the user UUID by {ID | userPrincipalName}?
A room looks like this (when read as a JSON object):
{
"id": "00000000-0000-0000-0000-000000000000"
"emailAdress": "room#company"
...
}
This works:
await graphClient.Users["room#company"].CalendarView.Request(queryOptions).GetAsync();
While this does not work:
await graphClient.Users["00000000-0000-0000-0000-000000000000"].CalendarView.Request(queryOptions).GetAsync();
When using the UUID I get (IDs not shown here):
Code: ErrorInvalidUser
Message: The requested user '<UUID>' is invalid
ClientRequestId: <some ID>
I did test this with a hardcoded room id and email but also with the ID object I get from calling the roomlist in C#.
Another inconsistency I encountered is that I can read the whole list of microsoft.graph.room via a http request but not using the C# Microsoft.Graph.Auth package. Reading the data of a room I know the email from does however work.
So does this just not work and the doc doesn't say so?
Does the Microsoft.Graph.Auth package not support those kind of requests?
Or do I use a wrong ID?
Saladino
According to some test, only when I use incorrect object id of user it shows same error message as yours.
If I use another user's object id(not object id of the user do authentication), it will show ErrorAccessDenied because do not have permission.
If I use the object id which the user not exist in Azure AD(incorrect object id), it will show same error message with yours. So please check if the uuid which you mentioned is the user's object id(shown in below screenshot) in your Azure AD and please check if you input the correct format of object id in your code by Console.WriteLine(object id)

How to add contact from two different Telegram servers?

Adding a contact from a country like Iran to a telegram account from Canada, causes an error says:
Unfortunately -name- has not joined telegram yet. But you can send
them an invitation.
I think that's because there are two different accounts from two different servers that aren't synced well.
Sometimes Iranian account can add Canadian account, and then Canadian can add Iranian as well, even if Iranian deletes Canadian from contacts. Or if a third person share their contacts or forward a message from one to another, they can add each other. I think these signs shows that telegram servers are not synced well.
As I'm using TLsharp to accomplish that, I can add two telegram accounts, one plays as that third person role, and shares Iranian contact to Canadian, and then he can save that contact.
My step by step plan is:
What I have is an Iranian Telegram account and Canadian one.
Iranian Customer opens my web site.
she/he fills telegram phone number field and submits.
we are going to start sending message in telegram by Canadian account.
try to add contact by Canadian account.
If failed, try to add contact by Iranian account. Else, we are done!
Share contact to Canadian Account.
Add contact by Canadian account.
My problem is:
how to have multiple telegram accounts in my code, because session file name is always "session.dat"
how to share contact in TLSharp
I can't forward message because there isn't any message yet. We should start messaging.
I also tried retrieving UserId and AccessHash by Iranian account, and using by Canadian account in this method:
await client.SendMessageAsync(new TLInputPeerUser() { UserId = xxx, AccessHash= yyyy}, "Hello");
but it has PEER_ID_INVALID error. (That is not true, I just took UserId from telegram!)
The problem is in number of contacts!
Telegram only supports about 1000 contacts (I found it experimental, there isn't any official source to prove this), and it will show you error when you want to add more contacts.
Trying to delete some contacts and reduce the count to 900, allowed me to add new contacts. So, the problem is not in telegram servers, it is in number of contacts limitation. Maybe they have a line of code like this:
Contact[] contacts = new Contact[1000]; //LOL
And for other two questions:
how to have multiple telegram accounts in my code, because session
file name is always "session.dat"
TLSharp.Core.TelegramClient clientAlt = new TLSharp.Core.TelegramClient(api_id, api_hash, sessionUserId: "sessionAlt");
There isn't any good documentation for TLSharp, but the problem solved by using sessionUserId as an optional parameter.
how to share contact in TLSharp?
TLInputMediaContact contact = new TLInputMediaContact()
{
FirstName = FirstName,
LastName = LastName,
PhoneNumber = PhoneNumber
};
TLRequestSendMedia req = new TLRequestSendMedia()
{
Media = contact,
Peer = new TLInputPeerUser() { UserId = AnotherTelegramAccountUserID.Id },
RandomId = UniqueNumber_ToPreventDuplicateMessages,
};
await clientAlt.SendRequestAsync<TLUpdates>(req);

google activity api limit result userid not working

i try to limit the list activity to a specific user but i always get the same results. i've tried users email address and the user id from the user list api function, both are not working.
i found a an open issue here, without an answer: https://code.google.com/p/google-apps-script-issues/issues/detail?can=2&start=0&num=100&q=&colspec=Stars%20Opened%20ID%20Type%20Status%20Summary%20Component%20Owner&groupby=&sort=&id=4974
my code:
ActivitiesResource.ListRequest listRequest = service.Activities.List();
listRequest.Source = "drive.google.com";
listRequest.DriveAncestorId = "root";
listRequest.UserId = "users email or Id";
listRequest.PageSize = 10;
IList<Activity> activities = listRequest.Execute().Activities;
additional info - i'm using a service account to authenticate
thanks
It is currently not possible to filter by user ID. Don't want to get into too many details, but the userId field has a different purpose that was never fully realized. Right now it's effectively ignored.

How to get user name, email, etc. from MobileServiceUser?

After a lot of digging around I've got my WPF application signing users in via Azure Mobile Service. My Mobile Service is connected to an Azure Active Directory that I have set up. However, when I log the user in with MobileServiceClient.LoginAsync(...) the MobileServiceUser UserId is in an unreadable hash it seems. For example it looks like: "Aad:X3pvh6mmo2AgTyHdCA3Hwn6uBy91rXXXXXXXXXX". What exactly is this?
I'd like to grab the user's display name to use but I can't figure out how.
That is the userID of Azure Active Directory. You need to create a service to expose your AAD info through a service and retrieve the additional information using the access token you get from your user.
First:
ServiceUser user = this.User as ServiceUser;
var identities = await user.GetIdentitiesAsync();
var aad = identities.OfType<AzureActiveDirectoryCredentials>().FirstOrDefault();
var aadAccessToken = aad.AccessToken;
var aadObjectId = aad.ObjectId;
This will give you the access token and objectID , then you need to query the information through AAD graphy API.
https://msdn.microsoft.com/library/azure/dn151678.aspx
Look at the sample request part. You should provide the query with the access token you got and objectId.
Here is an alternative approach, after reading http://justazure.com/azure-active-directory-part-2-building-web-applications-azure-ad/ scroll to the section on Identity in .Net it talks how claims are a standard part of the framework. So once you get the credentials object like provided by #beast
var aad = identities.OfType<AzureActiveDirectoryCredentials>().FirstOrDefault();
You can actually grab a dictionary with the various properties. Examples of some the properties can be found at https://msdn.microsoft.com/en-us/library/system.identitymodel.claims.claimtypes(v=vs.110).aspx
So from there you can do the following:
if (aad != null)
{
var d = aad.Claims;
var email = d[ClaimTypes.Email];
}
I did this to pull the user id which was cross referenced in a table. FYI I am using App Service, but I believe the credentials object is the same in Mobile Service

DirectoryEntry results in The server is unwilling to process the request

I am writing a small app that integrates with AD and will be listing users and allowing members of the site to edit certain fields of the users. These fields will be, first name, last name, display name and email.
When I run the following code I get an exception that says
The server is unwilling to process the request.
Please note that result is not null and contains the correct active directory user that I want to edit. Also note that result is of type SearchResult. Also note that the user I am using to connect to AD is the Administrative user.
DirectoryEntry entryToUpdate = result.GetDirectoryEntry();
entryToUpdate.Properties["cn"].Value = user.Name;
entryToUpdate.Properties["mail"].Value = user.Email;
entryToUpdate.Properties["sn"].Value = user.Surname;
entryToUpdate.Properties["displayName"].Value = user.DisplayName;
string username = user.Email.Substring(0, user.Email.IndexOf("#"));
entryToUpdate.Properties["sAMAccountName"].Value = username;
entryToUpdate.CommitChanges();
Any Ideas?
I believe
entryToUpdate.Properties["cn"].Value = user.Name;
is your Problem. Use givenName as first Name. "cn" is managed by the System.
Also:
If using Exchange, the Mail attribute is managed by it.
Consider the ramifications of modifing samAccountName. Users may not know how to log in, seperate Systems with pseudo SSO may not recognize them, the Login Name does not match the local Profile Name, etc.

Categories