我在使用 Google 新的 Admin SDK 时遇到困难。特别是使用 Oauth2 的 Directory API。
我想我已经快到了,但我在尝试使用 Directory API 检索用户详细信息时遇到了困难(我正在使用 Google Education Edition 域)。
基本上我想做的是编写一个 python 脚本,根据用户的注册状态(由我们的 AD 管理)来配置或取消配置用户。我有一个使用 Oauth1 执行此操作的脚本,但想将其更新为使用 Oauth2。
这是基于我找到的一些示例的代码片段。
f = file('test_key.p12', 'rb')
key = f.read()
f.close()
credentials = SignedJwtAssertionCredentials(
'[email protected] /cdn-cgi/l/email-protection',
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='j[email protected] /cdn-cgi/l/email-protection').execute(http=http)
pprint.pprint(lists)
这段代码似乎连接正确,但当我尝试执行查询时,出现 403 错误。
错误:https://www.googleapis.com/admin/directory/v1/users/[电子邮件受保护] /cdn-cgi/l/email-protection?alt=json 返回“未授权访问此资源/api”>
我的第一个想法是因为我还没有在管理员控制台上打开这个API(谷歌API控制台 https://code.google.com/apis/console/b/1/?pli=1#project:606346240424%3aservices) 但我有。 (实际上,我打开了 Admin SDK,而不是 Directory API,因为没有要打开的 Directory API,并且看到它是 Admin SDK 的一部分,它可以工作吗?)。
我是否还缺少其他步骤或者我在某个地方犯了一个愚蠢的错误?