使用cURL Google API从刷新令牌获取访问令牌 [英] Get Access Token from Refresh Token using cURL Google API
本文介绍了使用cURL Google API从刷新令牌获取访问令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用cURL从刷新令牌获取新的访问令牌?
在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
带卷曲的全流
# 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 Google API从刷新令牌获取访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文