【问题标题】:Get access token for google by using Python requests library使用 Python 请求库获取谷歌的访问令牌
【发布时间】:2019-08-18 11:20:35
【问题描述】:

试图获取访问令牌以响应谷歌,但无法弄清楚我做错了什么。

这是我到目前为止所做的:

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)

【问题讨论】:

  • 您收到的错误信息是什么?

标签: python python-requests access-token google-oauth


【解决方案1】:

您应该将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)

【讨论】:

  • 仍然无法正常工作:- {'error': 'invalid_grant', 'error_description': 'Bad Request'}
猜你喜欢
  • 2017-11-13
  • 2016-04-19
  • 2013-07-20
  • 2015-10-07
  • 2017-04-23
  • 2014-05-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多