我在使用Google新的Admin SDK时遇到困难。特别是使用Oauth2的Directory API。 我觉得我快到了,但是我试图使用Directory API检索用户详细信息(我正在使用Google教育版域)。Google管理API使用Oauth2获取服务帐户(教育版) - 403错误
基本上我想要做的是编写一个python脚本,根据他们的注册状态(由我们的AD管理)来提供或取消供应用户。我有一个使用Oauth1的脚本,但想更新它以使用Oauth2。
这是根据我发现的一些例子的代码片段。
f = file('test_key.p12', 'rb')
key = f.read()
f.close()
credentials = SignedJwtAssertionCredentials(
'[email protected]',
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='[email protected]').execute(http=http)
pprint.pprint(lists)
这段代码似乎连接正确,但是当我尝试执行查询时,出现403错误。
错误:https://www.googleapis.com/admin/directory/v1/users/[email protected]?alt=json返回 “无权访问该资源/ API”>
我的第一个想法是因为我没有在管理员控制台(Google API's console)上打开这个API,但我有。 (其实我打开了Admin SDK而不是Directory API,因为没有Directory API可以打开,看到它是Admin SDK的一部分,它可以工作?)。
是否有另一步我失踪或有我在某个地方犯了一个愚蠢的错误?
你知道了吗?我想知道Directory API(也就是Admin SDK API)是否可以与服务帐户和OAuth 2.0一起使用。 (我知道其他API可以)。我明白它可以使用OAuth 1.0,但我还没有尝试过。 –
@EricWalker - 是的见下面的评论。 – Bruce