gpt4 book ai didi

javascript - 在 Google Contacts API 版本 3.0 上使用 oauth2 检索刷新 token

转载 作者:行者123 更新时间:2023-11-29 22:25:00 26 4
gpt4 key购买 nike

我正在使用 oauth2(node.js 和 connect-oauth 库)连接到 google contacts API version 3.0 .

这样做,我会得到如下响应:

{ access_token : "...",
"token_typen": "Bearer",
"expires_in" : 3600,
"id_token": "..." }

我缺少用于在新访问 token 过期后立即获取新访问 token 的刷新 token 。

oauth2 的选项

{ host: 'accounts.google.com',
port: 443,
path: '/o/oauth2/token',
method: 'POST',
headers:
{ 'Content-Type': 'application/x-www-form-urlencoded',
Host: 'accounts.google.com',
'Content-Length': 247 } }

后正文 'redirect_uri=http%3A%2F%2Flocalhost%2Foauth2callback&grant_type=authorization_code&client_id=CLIENTID&client_secret=CLIENTSECRET&type=web_server&code=4%2F3gbiESZTEOjiyFPLUhKfE_a_jr8Q'

注意:我试图从 similar question 添加 approval_prompt=force到 request-post_body 但这导致了错误

{ statusCode: 400, data: '{\n  "error" : "invalid_request"\n}' }

最佳答案

NOTE: I tried to add approval_prompt=force from a similar question to the request-post_body but this resulted in an Error

请求 token 时不需要approval_prompt 参数。 *approval_prompt* 参数用于授权部分。


I am missing the refresh token...

您不会获得 *refresh_token* 的唯一方法是:

因此,尝试在授权码请求中添加:access_type=offline

编辑:

即:

https://accounts.google.com/o/oauth2/auth?client_id=**your_client_id**&scope=https://www.googleapis.com/auth/plus.me&redirect_uri=http://localhost&response_type=code&access_type=offline

如果您得到 400 是因为您添加了无效参数或缺少参数。

祝你好运!

关于javascript - 在 Google Contacts API 版本 3.0 上使用 oauth2 检索刷新 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10087429/

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