本文介绍了谷歌API的Python unauthorized_client:在未经授权的请求,客户端或范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试运行我的code,当我得到这个错误:

I get this error when trying to run my code:

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

下面是我的code:

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='[email protected]')

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

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

    print data

我的范围,我的控制台设置正确,我在我的控制台中启用自己的管理SDK。
我的电子邮件是一个超级管理员可以访问所有管理API的权限。

I have the scope set correctly in my console, and I have my Admin SDK enabled in my console.My email is a super admin with access to all Admin API Privileges.

为什么我会收到此错误?

Why would I be getting this error?

推荐答案

想通了:

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

You need to use the client ID from your "Developers Console" as the Client Name in the "Manage API client access" when you're setting your API scopes

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

这篇关于谷歌API的Python unauthorized_client:在未经授权的请求,客户端或范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 05:14