"invalid_scope" 尝试获取 oauth2 访问令牌时

"invalid_scope" when trying to get oauth2 access token

我正在关注 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 的文档中得到了上面的值,所以我不知道还有什么可以放在那里。

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

如该页面所述,此流程仅支持 limited set of scopes. Unfortunately this does not currently include the Google Photos Library API scopes

在问题跟踪器上打开了一个功能请求,以在此处添加对此 OAuth 流程的支持:https://issuetracker.google.com/113342106(您可以"star" 问题得到任何更新通知。)

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