尝试获取oauth2访问令牌时为“ invalid_scope”

时间:2018-09-15 18:03:57

标签: google-photos

我正在关注https://developers.google.com/photos/library/guides/authentication-authorization上的文档,并且相信下面的代码非常接近正确的代码...

import requests

# from https://developers.google.com/identity/protocols/OAuth2ForDevices#step-1-request-device-and-user-codes
def get_token(client_id="661666866149-42r2bldb8karc5bv5vltj0suis2fm4up.apps.googleusercontent.com"):
    response = requests.post(
        'https://accounts.google.com/o/oauth2/device/code',
        data={
            'client_id': client_id,
            'scope': 'https://www.googleapis.com/auth/photoslibrary https://www.googleapis.com/auth/photoslibrary.readonly.appcreateddata https://www.googleapis.com/auth/photoslibrary.sharing'
        })
    print(response.text)
    return response

以上内容始终失败

{ "error": "invalid_scope" } <Response [400]>

但是,如果我将scope的值更改为email,那是可行的。我从google的文档中获得了上述价值,所以我不知道该放在哪里。

1 个答案:

答案 0 :(得分:1)

您似乎正在遵循OAuth 2.0 for TV and Limited-Input Device Applications的指南来授权电视或类似设备上的OAuth用户范围。

如该页面所述,该流程仅支持limited set of scopes。不幸的是,当前不包括Google Photos Library API scopes

问题跟踪器上有一个功能请求正在打开,以在此处添加对此OAuth流的支持:https://issuetracker.google.com/113342106(您可以为问题加注星标,以便在收到任何更新时得到通知。)

(如果您的流程涉及移动设备和服务器组件,则您可以完成与Google sign-in by exchanging user credentials between your server and Google Services类似的操作。您可以提示用户在您的应用中授权范围,并在与服务器交换令牌后,以这种方式进行API调用。您必须自己处理电视/有限输入设备与您的应用之间的链接。)

相关问题