Получить токен доступа для Google с помощью библиотеки запросов Python - PullRequest
0 голосов
/ 27 марта 2019

Пытаюсь получить токен доступа в ответ на Google, но не могу понять, что я делаю неправильно.

Это то, что я сделал до сих пор:

import requests

authorization_code_req = {
    'client_id':'key',
    'client_secret':'key',
    'redirect_uri':'http://localhost:5000',
    'grant_type':'authorization_code'}

r = requests.get('https://accounts.google.com/o/oauth2/token',
                 params=authorization_code_req)

print (r)

1 Ответ

1 голос
/ 30 марта 2019

вы должны отправить authorization_code_req как json, а не как params. Итак, ваш код должен выглядеть примерно так:

import requests

authorization_code_req = {
    'client_id':'key',
    'client_secret':'key',
    'redirect_uri':'http://localhost:5000',
    'grant_type':'authorization_code'
}

r = requests.get('https://accounts.google.com/o/oauth2/token',
                 json=authorization_code_req)

print(r)
...