Google OAuth API 令牌请求出现 404 错误

the*_*oid 3 python oauth google-api google-oauth

我正在尝试从 Google OAuth api 获取令牌。我已经成功获得临时授权码。

但是,我的请求返回 404 错误,并显示正常的 Google“这是一个错误”404 页面。这是我的Python代码:

data = {
    "code":auth_code,
    "client_id":client_id,
    "client_secret":client_secret,
    "redirect_uri":redirect_uri,
    "grant_type":"authorization_code"
    }
headers = {"Content-Type":"application/x-www-form-urlencoded"}
r = requests.post("https://googleapis.com/oauth/v4/token",data=data,headers=headers)
Run Code Online (Sandbox Code Playgroud)

无论我是否对参数进行 url 编码,我都会遇到相同的错误(我认为 requests 库无论如何都会这样做)。

这是我发送的更详细的数据(当然经过审查)

'client_id':'2-------------------------------------------0.apps.googleusercontent.com',
'client_secret': '5----------------------p',
'code': '4/A-------------------------- ... ------------------------------------fGE#',
'grant_type': 'authorization_code',
'redirect_uri': 'https://localhost'
Run Code Online (Sandbox Code Playgroud)

我知道这里的问题与我的非常相似,但提供的所有解决方案要么不起作用(url 编码),要么不适用(其他所有内容)。

我使用这个官方文档作为参考。

这可能是非常明显的,就像我在这里提出的大多数问题一样。

编辑-我试过了

data = "code="+auth_code+"&client_id="+client_id+"&client_secret="+client_secret+"&redirect_uri="+redirect_uri+"&grant_type=authorization_code"
Run Code Online (Sandbox Code Playgroud)

...返回 400。有或没有 url 编码。

Jac*_*k M 9

对我来说,问题是我正在发送 GET。您必须发送一个帖子。