小编Jul*_*ing的帖子

Google API范围已更改

编辑:我通过在我的示波器中添加" https://www.googleapis.com/auth/plus.me " 轻松解决了这个问题,但我想开始讨论这个主题,看看是否有其他人遇到了同样的问题.

我在GCP上运行了一项服务,这是一个使用Google API的应用引擎.今天早上,我收到了这条"警告"消息,该消息引发了500错误.它在过去一个月一直运作良好,今天只发出此错误(在此帖之前5小时).

有谁知道为什么Google在oauth2callback上返回了另一个范围?非常感谢任何其他见解.如果你之前见过这个,请告诉我.我无处可寻.

异常类型:/ oauth2callback警告

例外值:范围已从" https://www.googleapis.com/auth/userinfo.email " 更改为" https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com /auth/plus.me ".

这一行引发了错误:

flow.fetch_token(
        authorization_response=authorization_response,
        code=request.session["code"])
Run Code Online (Sandbox Code Playgroud)

返回网址是https://my_website.com/oauth2callback?state=SECRET_STATE&scope=https://www.googleapis.com/auth/userinfo.email+https://www.googleapis.com/auth/plus.me#

而不是通常的https://my_website.com/oauth2callback?state=SECRET_STATE&scope=https://www.googleapis.com/auth/userinfo.email#

编辑:示例代码

import the required things

SCOPES = ['https://www.googleapis.com/auth/userinfo.email',
          'https://www.googleapis.com/auth/calendar',
          # 'https://www.googleapis.com/auth/plus.me' <-- without this, it throws the error stated above. adding it, fixes the problem. Google returns an additional scope (.../plus.me) which causes an error.
          ]

def auth(request):
    flow = google_auth_oauthlib.flow.Flow.from_client_secrets_file(
        CLIENT_SECRETS_FILE, scopes=SCOPES)
    flow.redirect_uri = website_url + '/oauth2callback'
    authorization_url, state = flow.authorization_url(
        access_type='offline', include_granted_scopes='true', …
Run Code Online (Sandbox Code Playgroud)

django google-api python-3.x google-oauth

8
推荐指数
1
解决办法
2127
查看次数

标签 统计

django ×1

google-api ×1

google-oauth ×1

python-3.x ×1