gpt4 book ai didi

javascript - 从授权码google oauth2获取刷新 token

转载 作者:太空宇宙 更新时间:2023-11-04 01:55:09 25 4
gpt4 key购买 nike

我正在尝试获取刷新和访问 token 的 Exchange 授权代码。

这是我发送给 Google 的通话后数据。

var requestBody = {
code:**mycode**,
grant_type:'authorization_code',
client_secret: **mysecret**,
client_id: **clientId**,
redirect_uri:"http://localhost:3000"
}

我通过 POST 调用将此数据发送到“https://www.googleapis.com/oauth2/v4/token

使用 meteor 后调用

Meteor.http.call('POST', requestUrl, {'data': requestBody});

但我从 Google 收到此错误。

Error: failed [400] {  "error": "unsupported_grant_type",  "error_description": "Invalid grant_type: " } 

知道为什么我会收到此错误。

理想情况下它应该返回

{
"access_token":"sometoken",
"expires_in":3920,
"token_type":"Bearer",
"refresh_token":"refresh token"
}

最佳答案

确保发送帖子时正文位于 HTTP URL 查询参数中,而不是作为 Json 发布。

code=4/X9lG6uWd8-MMJPElWggHZRzyFKtp.QubAT_P-GEwePvB8fYmgkJzntDnaiAI&client_id={ClientId}.apps.googleusercontent.com&client_secret={ClientSecret}&redirect_uri=urn:ietf:wg:oauth:2.0:oob&grant_type=authorization_code

帖子的内容类型也应该是“application/x-www-form-urlencoded”,而不是JSON

关于javascript - 从授权码google oauth2获取刷新 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48253979/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com