繁体   English   中英

使用Python请求库获取Google的访问令牌

[英]Get access token for google by using Python requests library

试图获取访问令牌作为对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)

您应该以json而不是params发送authorization_code_req 因此,您的代码应如下所示:

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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM