oauth2client.client - 收到没有 refresh_token 的令牌响应。考虑使用 prompt='consent' 重新验证
oauth2client.client - Received token response with no refresh_token. Consider reauthenticating with prompt='consent'
我从移动应用程序收到 google 授权代码并使用 python oauth2client 交换访问令牌和刷新令牌,如下所示:
credentials = client.credentials_from_clientsecrets_and_code(
app.config.get('GG_APP_SECRET'),
['profile'],
authCodeFromMobileApp,
redirect_uri='http://example.com')
然后我收到了:
Received token response with no refresh_token. Consider
reauthenticating with prompt='consent'.
根据this,它说我必须设置:access_type=offline
但我不太确定where/how在oauth2client中设置这个?
这里有人解决过这个问题吗?
加法:
下面我也试过了:
flow = client.flow_from_clientsecrets(app.config.get('GG_APP_SECRET'),
['profile'],
message=None,
cache=None,
redirect_uri='http://example.com',
device_uri=None)
flow.params['access_type'] = 'offline'
credentials = flow.step2_exchange(req_gg_code, http=None)
但还是有同样意想不到的结果...
flow_from_clientsecrets 方法有一个名为 prompt 的参数,您可以传递一个值 "consent"
flow = client.flow_from_clientsecrets(
app.config.get('GG_APP_SECRET'),
['profile'],
message=None,
cache=None,
redirect_uri='http://example.com',
device_uri=None,
prompt='consent'
)
现在每次都会征求用户同意,每次使用都会得到一个refresh_token。
我从移动应用程序收到 google 授权代码并使用 python oauth2client 交换访问令牌和刷新令牌,如下所示:
credentials = client.credentials_from_clientsecrets_and_code(
app.config.get('GG_APP_SECRET'),
['profile'],
authCodeFromMobileApp,
redirect_uri='http://example.com')
然后我收到了:
Received token response with no refresh_token. Consider reauthenticating with prompt='consent'.
根据this,它说我必须设置:access_type=offline
但我不太确定where/how在oauth2client中设置这个?
这里有人解决过这个问题吗?
加法:
下面我也试过了:
flow = client.flow_from_clientsecrets(app.config.get('GG_APP_SECRET'),
['profile'],
message=None,
cache=None,
redirect_uri='http://example.com',
device_uri=None)
flow.params['access_type'] = 'offline'
credentials = flow.step2_exchange(req_gg_code, http=None)
但还是有同样意想不到的结果...
flow_from_clientsecrets 方法有一个名为 prompt 的参数,您可以传递一个值 "consent"
flow = client.flow_from_clientsecrets(
app.config.get('GG_APP_SECRET'),
['profile'],
message=None,
cache=None,
redirect_uri='http://example.com',
device_uri=None,
prompt='consent'
)
现在每次都会征求用户同意,每次使用都会得到一个refresh_token。