【发布时间】:2018-12-27 02:55:01
【问题描述】:
编辑:我通过将“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"])
编辑:示例代码
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',
prompt='consent')
request.session["state"] = state
return redirect(authorization_url)
def oauth2callback(request):
...
# request.session["code"] = code in url
authorization_response = website_url + '/oauth2callback' + parsed.query
flow.fetch_token(
authorization_response=authorization_response,
code=request.session["code"])
...
【问题讨论】:
-
最近有任何代码更改吗?
-
你调用的是什么API,什么方法?
-
请编辑您的问题并包含stackoverflow.com/help/mcve
-
@Umair 没有代码更改。
-
@ScottMcC 在调用 api "googleapis.com/userinfo/v2/me" 之前抛出了错误
标签: django python-3.x google-api google-oauth