gpt4 book ai didi

curl - 使用cURL Google API从刷新 token 获取访问 token

转载 作者:行者123 更新时间:2023-12-03 15:55:44 28 4
gpt4 key购买 nike

如何使用cURL从刷新 token 中获取新的访问 token ?

在PHP中,我将执行以下操作:

$client = new Google_Client();
$client->addScope(Google_Service_Analytics::ANALYTICS_READONLY);
$client->refreshToken($refresh_token);
$access_token = $client->getAccessToken();

如何使用cURL完成同一件事?

我无法从他们的 documentation中找到它。

最佳答案

这是我使用的代码:

# Exchange a refresh token for a new access token.
curl \
--request POST \
--data 'client_id=[Application Client Id]&client_secret=[Application Client Secret]&refresh_token=[Refresh token granted by second step]&grant_type=refresh_token' \
https://accounts.google.com/o/oauth2/token
Link to gist

cURL的完整流程
# Client id from Google Developer console
# Client Secret from Google Developer console
# Scope this is a space seprated list of the scopes of access you are requesting.

# Authorization link. Place this in a browser and copy the code that is returned after you accept the scopes.
https://accounts.google.com/o/oauth2/auth?client_id=[Application Client Id]&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=[Scopes]&response_type=code

# Exchange Authorization code for an access token and a refresh token.

curl \
--request POST \
--data "code=[Authentcation code from authorization link]&client_id=[Application Client Id]&client_secret=[Application Client Secret]&redirect_uri=urn:ietf:wg:oauth:2.0:oob&grant_type=authorization_code" \
https://accounts.google.com/o/oauth2/token

# Exchange a refresh token for a new access token.
curl \
--request POST \
--data 'client_id=[Application Client Id]&client_secret=[Application Client Secret]&refresh_token=[Refresh token granted by second step]&grant_type=refresh_token' \
https://accounts.google.com/o/oauth2/token

关于curl - 使用cURL Google API从刷新 token 获取访问 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58285683/

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