根据 doc,如果您想刷新访问令牌,可以通过提供 client_id、client_secret、grant_type、refresh_token 对“https://oauth2.googleapis.com/token”进行 HTTP 调用。
代码:
user = User.query.filter_by(email='daniyaldehleh@gmail.com').first()
with open('client_secret.json') as d:
d = json.load(d)
thecredentials = {
'client_id': d['web']['client_id'],
'client_secret':d['web']['client_secret'],
'refresh_token':user.refresh,
'grant_type': user.refresh,
'redirect_uri': "http://localhost:5000/",
'access_type':'offline'
}
req = requests.post(url='https://oauth2.googleapis.com/token', data = thecredentials)
print(req.text)
return str(req)
尽管根据一些研究添加了 'redirect_uri' 和 'access_type',但我继续得到:
{
"error": "unsupported_grant_type",
"error_description": "Invalid grant_type: 1//04JBbHWUWxwS3CgYIARAAGAQSNwF-L9IrZyyrHpxIoerJ4XZkAuGosXeeRHiYvdEQG7uF5EO5jWSC_-9mrRMAhmM30JHZvgyIhbM"
}
答案 0 :(得分:1)
对于使用刷新令牌,授权类型应为:grant_type = refresh_token
。
见https://developers.google.com/android-publisher/authorization#using_the_refresh_token