I'm having difficulty using the Google new Admin SDK. In particular, the directory API using Oauth2. I think I'm almost there, but I'm stuck trying to get user information using the Directory API (I use the Google Education Edition domain).
Basically what I'm trying to do is write a python script that sets or cancels the use of users based on their registration status, which our AD manages. I have a script that does this using Oauth1, but wants to update it to use Oauth2.
Here is a code snippet based on some examples that I found.
f = file('test_key.p12', 'rb') key = f.read() f.close() credentials = SignedJwtAssertionCredentials( ' 606346240424-10stfco1ukj9h4m4b4r40@developer.gserviceaccount.com ', key, scope= 'https://www.googleapis.com/auth/admin.directory.user') http = httplib2.Http() http = credentials.authorize(http) service = build(serviceName='admin', version='directory_v1', http=http) lists = service.users().get(userKey=' joe.blogs@mydomain.com ').execute(http=http) pprint.pprint(lists)
This part of the code looks correct, but when I try to execute the request, I get a 403 error.
ERROR: https://www.googleapis.com/admin/directory/v1/users/ joe.blogs@mydomain.com ? Alt = json returns "Not authorized to access this resource / api">
My first thought was that I did not enable this API in the Admin console ( Google API Console ), but I have one. (Actually, I included the administrator SDK, not the directory API, because the directory API is not included and seeing that it is part of the administrator SDK, will it work?).
Is there another step that I am missing, or have I made a stupid mistake somewhere?
Bruce
source share