#python #http #google-api #google-calendar-api #google-api-python-client
#python #http #google-api #google-calendar-api #google-api-python-client
Вопрос:
Согласно документу, если вы хотите обновить свой токен доступа, вы можете выполнить HTTP-вызов «https://oauth2.googleapis.com/token » с предоставлением client_id, client_secret, grant_type, refresh_token.
Код:
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"
}
Комментарии:
1. Описание ошибки понятно. Вы не вводите
refresh_token
asgrant_type
, а вводите токен обновления.2. разве это не одно и то же? Честно говоря, я был смущен конкретно. Должно ли это быть что-то вроде этого:
refresh_token = user.refresh thecredentials = { 'client_id': d['web']['client_id'], 'client_secret':d['web']['client_secret'], 'refresh_token':refresh_token, 'grant_type': refresh_token}
3. Было бы здорово, если бы вы могли уточнить это с помощью примера кода или чего-то еще.
4. В этом случае значение
grant_type
должно бытьrefresh_token
равно . Поэтому, пожалуйста, измените'grant_type': user.refresh,
'grant_type': 'refresh_token',
и протестируйте его еще раз.5. о, окк. Большое вам спасибо!!
Ответ №1:
Для использования токенов обновления тип гранта должен быть: grant_type = refresh_token
.
Видишь https://developers.google.com/android-publisher/authorization#using_the_refresh_token