Google API Client users().get(userKey='name@do

2019-09-09 13:00发布

I'm trying to see if an email account with name@domain.com already exists but I keep getting this error:

googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/admin/directory/v1/users/name%domain.comL?alt=json returned "Not Authorized to access this resource/api">

Although I successfully use the users().insert() method from my code with the same credentials. I've tried the "Try it" webpage for this exact request and noticed two things.

  1. It worked with the same scopes I'm using (listed below)
  2. The GET URL they are providing is https://www.googleapis.com/admin/directory/v1/users/name%40domain.com?key={YOUR_API_KEY} and not https://www.googleapis.com/admin/directory/v1/users/name%domain.comL?alt=json. I'm just guessing this is just using the OAuth generated key right in the URL.

I'm writing in Python and use google api for python https://github.com/google/google-api-python-client/tree/master/googleapiclient.

The scopes that I'm using:

'https://www.googleapis.com/auth/admin.directory.user',
'https://www.googleapis.com/auth/drive',
'https://www.googleapis.com/auth/spreadsheets'

0条回答
登录 后发表回答