Note that there are some explanatory texts on larger screens.

plurals
  1. POHas anyone got Google DirectoryService.Users.List().Execute(); to work in C#/.NET?
    text
    copied!<p>I've been trying to list users in my google apps domain for a while now. No problem in Python, but in C# i get an error message: An error has occured: Google.Apis.Requests.RequestError Bad Request [400] Errors [ Message[Bad Request] Location[ - ] Reason[badRequest] Domain[global] ]</p> <p>I'm no C# guru of any sorts but when I looked through the Google.Apis.Admin.directory_v1.cs - file it looked to me as if the UserResource ListRequest is wrong??? It's found on line 7349-7352 in the file. Anyone know's if it's not yet implemented in the API?</p> <p>Edit: I start with why I <em>THINK</em> the code in Google.Apis.Admin.directory_v1.cs, lines 7349-7352 is wrong(as I mentioned - I'm not a C#-guru): </p> <h2>The Code:</h2> <pre><code> /// &lt;summary&gt;Retrieve either deleted users or all users in a domain (paginated)&lt;/summary&gt; public virtual ListRequest List() { return new ListRequest(service); } </code></pre> <hr> <h2>Why I find it odd:</h2> <p>I can' see where to pass the customerid or domain as an argumant to this request, but in the APIs Explorer it's needed (otherwise I get the same error message as above, in my original post).</p> <p>Edit : I looked a bit further down in the file and I guess that line 8904 and onwards is doing what I looked for earlier. My Bad!</p> <p>But still I can't get my code to work?!?!?</p> <hr> <h2>And my code that won't work:</h2> <pre><code>static void Main(string[] args) { // Display the header and initialize the sample. CommandLine.EnableExceptionHandling(); Console.WriteLine("List users in a google apps domain!"); Console.WriteLine("by Jonas Bergstedt 2013"); // Get the domainname Console.Write("Domain: "); string domain = Console.ReadLine(); // Register the authenticator. var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description) { ClientIdentifier = &lt;myClientId&gt;, ClientSecret = &lt;myClientSecret&gt;", }; var auth = new OAuth2Authenticator&lt;NativeApplicationClient&gt;(provider, GetAuthorization); // Create the service. var service = new DirectoryService(new BaseClientService.Initializer() { Authenticator = auth, ApplicationName = "List Users", ApiKey = &lt;myApiKey&gt; }); // Trying to add the domain service.Users.List().Domain = domain; Users results = service.Users.List().Execute(); foreach (User list in results.UsersValue) { Console.WriteLine("- " + list.Name); } } private static IAuthorizationState GetAuthorization(NativeApplicationClient arg) { // Get the auth URL: IAuthorizationState state = new AuthorizationState(new[] { DirectoryService.Scopes.AdminDirectoryUser.GetStringValue() }); state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl); Uri authUri = arg.RequestUserAuthorization(state); // Request authorization from the user (by opening a browser window): Process.Start(authUri.ToString()); Console.WriteLine(); Console.Write("Authorization Code: "); string authCode = Console.ReadLine(); // Retrieve the access token by using the authorization code: return arg.ProcessUserAuthorization(authCode, state); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload