本文介绍了获取刷新令牌 google api的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码无法获取刷新令牌.我只能获取我的访问令牌、令牌类型等,我遵循了一些教程,例如将 access_type=offline
放在我的登录 URL 上:
I can't get my refresh token with my code. I can only get my access token, token type etc.,I have followed some tutorials like putting access_type=offline
on my login URL:
echo "<a href='https://accounts.google.com/o/oauth2/auth?"
. "access_type=offline&client_id=123345555.apps.googleusercontent.com& "
. "scope=https://www.googleapis.com/auth/calendar+https://www.googleapis.com/auth/plus.me&response_type=code& "
. "redirect_uri=http://www.sample.com/sample.php&state=/profile'>Google</a>";
以及我获取访问令牌的字段:
and my fields in getting the access token:
$fields=array(
'code'=> urlencode($authcode),
'client_id'=> urlencode($clientid),
'client_secret'=> urlencode($clientsecret),
'redirect_uri'=> urlencode($redirecturi),
'grant_type'=> 'authorization_code',
);
但我无法获得refresh_token,只有access_token、token_type、id_token 和expires_in.
but I can't get refresh_token, just the access_token, token_type, id_token and expires_in.
推荐答案
通过将其添加到您的 url 参数中发现
Found out by adding this to your url parameters
更新:
改用access_type=offline&prompt=consent
.
approval_prompt=force
不再有效https://github.com/googleapis/oauth2client/issues/453
这篇关于获取刷新令牌 google api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!