Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use 2 legged oauth on Google Admin Directory API
    primarykey
    data
    text
    <p>I am trying to write code to get all user accounts in our Google Apps domain using Google Admin Directory API with 2 Legged OAuth. Unfortunately, I can hardly find any documents or sample code for directory API. I tried the code below:</p> <pre><code>AdminService adminService = new AdminService(); Google.Apis.Authentication.OAuth2LeggedAuthenticator authenticator= new Google.Apis.Authentication.OAuth2LeggedAuthenticator(mydomainName, domainConsumerSecret, adminId, mydomainName); UsersResource usrRes = new UsersResource(adminService, authenticator); UsersResource.ListRequest listReq = usrRes.List(); Google.Apis.Admin.directory_v1.Data.Users allUsers = listReq .Fetch(); foreach (Google.Apis.Admin.directory_v1.Data.User usr in allUsers.UsersValue) { ... } </code></pre> <p>But I got the 401 unauthorized error. Then I tried the low level way using the old GData Lib.</p> <pre><code>Google.GData.Client.OAuth2LeggedAuthenticator authenticator = new OAuth2LeggedAuthenticator("MyAPP", mydomainName, domainConsumerSecret,adminId, mydomainName, "HMAC-SHA1"); HttpWebRequest request = authenticator.CreateHttpWebRequest("GET", new Uri("https://www.googleapis.com/admin/directory/v1/users?domain=mydomain.com")); HttpWebResponse response = request.GetResponse() as HttpWebResponse; </code></pre> <p>the above code got the same 401 error. </p> <p>Based on the source code of Directory API, I think 2LO is supported. However, I just cannot make it work. Anyone can help to point out my problem? Thanks.</p> <p>Another question: Is the userid (xoauth_requestor_id parameter) necessary for 2LO directory API request? I know this parameter is required for other APIs when using 2LO, but not clear if it is required for the Directory and Provisioning API. </p> <p>BTW: I would like to construct the 2LO HTTP requests from scratch without using any lib, but I haven't started this yet. I need to make sure that 2LO works on the Directory API requests.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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