Google API Python unauthorized_client:请求中未经授权的客户端或范围

And*_*rew 9 python api google-api python-2.7

尝试运行我的代码时出现此错误:

oauth2client.client.AccessTokenRefreshError: unauthorized_client: Unauthorized client or scope in request.
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

import json
import requests
import httplib2
from oauth2client.client import SignedJwtAssertionCredentials
from apiclient.discovery import build

if __name__ == '__main__':

    json_key_file = 'my-key.json'

    with open(json_key_file) as json_file:

        json_data = json.load(json_file)
        credential = SignedJwtAssertionCredentials(json_data['client_email'], json_data['client_email'], json_data['private_key'], scope=['https://www.googleapis.com/auth/admin.directory.user','https://www.googleapis.com/auth/admin.directory.user.readonly'], sub='myemail@domain.com')

    http = httplib2.Http()
    http = credential.authorize(http)

    service = build('admin', 'directory_v1', http=http)
    data = service.users().list(domain='domain.com').execute()

    print data
Run Code Online (Sandbox Code Playgroud)

我在控制台中正确设置了范围,并且在控制台中启用了我的Admin SDK.我的电子邮件是超级管理员,可以访问所有Admin API权限.

为什么我会收到此错误?

And*_*rew 11

弄清楚了:

在设置API范围时,需要使用"开发人员控制台"中的客户端ID作为"管理API客户端访问"中的客户端名称

https://developers.google.com/+/domains/authentication/delegation