我在使用Google的目录API从电子邮件组中提取用户列表时遇到问题。这是我的代码:
CLIENT_SECRET = 'group_auth.p12'
CLIENT_EMAIL = "USER@developer.gserviceaccount.com"
with open(CLIENT_SECRET, "rb") as f:
PRIVATE_KEY = f.read()
f.close()
credentials = SignedJwtAssertionCredentials(CLIENT_EMAIL, PRIVATE_KEY, scope="https://www.googleapis.com/auth/admin.directory.group.readonly")
http = httplib2.Http()
http = credentials.authorize(http)
service = build("admin", "directory_v1", http)
request = service.members().get(groupKey=*taken-out*, memberKey="")
response = request.execute()
这是我收到的错误:
No handlers could be found for logger "oauth2client.util"
Traceback (most recent call last):
File "google_group_membership.py", line 21, in <module>
response = request.execute()
File "/Users/jleung/googleapi/lib/python2.7/site-packages/oauth2client/util.py", line 137, in positional_wrapper
return wrapped(*args, **kwargs)
File "/Users/jleung/googleapi/lib/python2.7/site-packages/googleapiclient/http.py", line 729, in execute
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/admin/directory/v1/groups/itgroup%40appdynamics.com/members/?alt=json returned "Not Authorized to access this resource/api">
在我的谷歌控制台中,我确保我的Google API服务帐户具有正确的权限。任何帮助将不胜感激
谢谢
答案 0 :(得分:1)
想出来,我必须去我的谷歌域管理面板并在安全设置下 - &gt;高级设置 - &gt;管理API客户端访问
我必须在那里添加我的客户端ID和范围