Google API PHP刷新令牌返回NULL [英] Google API PHP Refresh Token returns NULL

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

问题描述

我使用PHP的Google API客户端库进行离线身份验证,但是当使用此代码时:

  $这 - > google-> refreshToken($结果[ google_refresh_token])); 

它返回NULL。

$ this-> google 指的是Google_Client类的一个实例。



任何人都知道这可能是什么?



如果我尝试更改给定的刷新令牌,它将返回Google异常错误,因此它应该是有效的令牌。





编辑:

 'client_id' => 'myclientid',
'client_secret'=> 'myclientsecret',
'redirect_uri'=> 'mypage',
'developer_key'=> 'mydeveloperkey',

//其他参数。
'access_type'=> 'offline',
'approval_prompt'=> 'force',

也许这会帮助你

refresh_token()方法。
我只保存来自第一个请求的整个JSON响应,并将其提供给 setAccesToken()方法。如果访问令牌到期,它将自动从给定的JSON中获得一个新的。


I'm using the Google APIs Client Library for PHP for offline authentication, but when I use this code:

$this->google->refreshToken($result["google_refresh_token"]));

it returns NULL.

$this->google refers to an instance of the Google_Client class.

Anyone an idea what this could be?

If I try to change the given refresh token it returns a Google Exception Error, so it should be a valid token.

Thank you!

Edit:

'client_id' => 'myclientid',
      'client_secret' => 'myclientsecret',
      'redirect_uri' => 'mypage',
      'developer_key' => 'mydeveloperkey',

      // Other parameters.
      'access_type' => 'offline',
      'approval_prompt' => 'force',

Maybe this helps you

解决方案

I now use a really simple method to avoid the refresh_token() method. I just save the whole JSON response from the first request and give this to the setAccesToken() method. If the access token expires, it will automatically get a new one from the given JSON.

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

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