python - 谷歌 API Python unauthorized_client : Unauthorized client or scope in request

标签 python api python-2.7 google-api

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

oauth2client.client.AccessTokenRefreshError: unauthorized_client: Unauthorized client or scope in request.

这是我的代码:

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

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

为什么会出现此错误?

最佳答案

想通了:

当您设置 API 范围时,您需要使用“开发者控制台”中的客户端 ID 作为“管理 API 客户端访问”中的客户端名称

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

关于python - 谷歌 API Python unauthorized_client : Unauthorized client or scope in request,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27282788/

相关文章:

python - Tkinter 添加选项卡将所有内容推到右侧

python - 没有窗口的Tkinter消息框?

python - worker /时隙排列/约束过滤算法

json - 为什么我的 GET 请求不适用于 Wikipedia API,但适用于任何其他 API?

api - 如何代表卖家使用亚马逊产品广告 API

python - 复制 pandas 数据框中的列

python - 使用 pandas 中 dataframe1 中某一列的值查找 dataframe2 中特定列的值

api - 在艺术家的轨道中搜索 - Spotify API

image - 如何验证此 URL 重定向到图像?

python - 替换字典中的键