Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用已在googledrive api中检索到的refreshtoken获取新的accesstoken_Php_Google Drive Api - Fatal编程技术网

Php 使用已在googledrive api中检索到的refreshtoken获取新的accesstoken

Php 使用已在googledrive api中检索到的refreshtoken获取新的accesstoken,php,google-drive-api,Php,Google Drive Api,我在php中使用Gooogledrive Api。使用它,我从凭证部分检索了刷新令牌。accesstoken在3600秒后过期。我的问题是如何从该刷新令牌获取新的accesstoken。我使用了Google php客户端库中给出的方法。我调用了refreshtoken('refreshtoke')apiclient的函数。我的代码如下 $client = new apiClient(); $client->setClientId('my-client-id'); $client->s

我在php中使用Gooogledrive Api。使用它,我从凭证部分检索了刷新令牌。accesstoken在3600秒后过期。我的问题是如何从该刷新令牌获取新的accesstoken。我使用了Google php客户端库中给出的方法。我调用了refreshtoken('refreshtoke')apiclient的函数。我的代码如下

$client = new apiClient();
$client->setClientId('my-client-id');
$client->setClientSecret('my client-secret-key');
$client->setRedirectUri('my redirect uri');



$client->refreshToken('MY-retrieved-refresh-token');
但我得到了以下错误:- 未捕获的异常“apiAuthException”,消息“刷新OAuth2令牌时出错,消息:“{”错误“:“无效的授权”}**


请帮帮我。rest一切正常。但是accesstoken在3600秒后过期,并且在这行代码之后不会刷新

 $client->refreshToken('MY-retrieved-refresh-token');
//这样做

 $token = $client->getAccessToken(); 

//这将为您提供json编码字符串,该字符串将具有访问、刷新令牌和承载等功能。

您是否设置了访问和刷新令牌?我没有看到$client->SetAccessToken($tokens)这一行,其中$tokens将是jSON中的访问和刷新令牌。谢谢vicrabb。我明白你的意思。是这样还是你仍然有问题?嗨@vicrabb,我遇到了同样的问题,你能帮我举个例子吗?网上有很多东西,但没有一个是清楚的。提前多谢!当需要刷新令牌时,需要对其进行设置。如果您没有将行$client->SetAccessToken($tokens)(其中$tokens以jSON格式保存您的访问和刷新令牌),您就没有刷新它们的权限。我没有一个例子,因为我没有使用refreshToken()函数。哦,天哪……在调试这个问题将近一个月后,我把这两行代码倒过来了。在切换它们之后,现在就可以工作了,而无需在每次访问令牌过期时重新进行身份验证。非常感谢你发布这个Josh。