获取刷新令牌Google API [英] Get refresh token google api

查看:170
本文介绍了获取刷新令牌Google API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法通过代码获得刷新令牌。我只能获取访问令牌,令牌类型等。
我遵循了一些教程,例如在登录URL上放置 access_type = offline

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.

推荐答案

通过将其添加到您的网址参数中找到

Found out by adding this to your url parameters

approval_prompt = force

更新:

改为使用 access_type = offline& prompt =同意

approval_prompt = force 不再有效
> https://github.com/googleapis/oauth2client/issues/453

这篇关于获取刷新令牌Google API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆