Google API Client users().get(userKey='name@domain.com') returns Not Authorized to access this resource/api

末鹿安然 提交于 2019-12-12 05:03:24

问题


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'

来源:https://stackoverflow.com/questions/37357373/google-api-client-users-getuserkey-namedomain-com-returns-not-authorized

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!