Google API Client users().get(userKey='名称@domain.com')返回未授权访问此资源/api

2024-06-28 17:52:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试查看是否已存在具有name@domain.com的电子邮件帐户,但我一直收到以下错误:

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">

虽然我使用相同的凭据成功地使用了代码中的users().insert()方法。 我尝试了"Try it"网页来获得这个确切的请求,并注意到两件事。在

  1. 它的作用域与我使用的相同(如下所示)
  2. 他们提供的GET URL是https://www.googleapis.com/admin/directory/v1/users/name%40domain.com?key={YOUR_API_KEY} 而不是https://www.googleapis.com/admin/directory/v1/users/name%domain.comL?alt=json。我猜这只是在URL中使用OAuth生成的密钥。在

我用Python编写,并使用googleapi for Pythonhttps://github.com/google/google-api-python-client/tree/master/googleapiclient。在

我使用的范围:

^{pr2}$

Tags: httpscomapijsonadmindomainwwwalt