【发布时间】:2016-08-21 22:03:55
【问题描述】:
我正在使用 Google API 连接到 AdSence,并且我需要我的脚本在后台运行 - 这意味着无需用户干预。
我正在用 PHP 编写代码。这就是我创建令牌的方式:
$token = array(
'access_token' => 'XXXX',
'refresh_token' => 'XXXX',
'expires_in' => 3600,
'token_type' => 'Bearer',
"created" => 1461760640
);
$json_token = json_encode($token);
$client->setAccessToken($json_token);
现在,令牌的生命周期是一小时。 我需要刷新脚本中的令牌 - 并将新令牌插入“$token”变量 - 这样我的脚本才能单独运行。
我正在使用两个 Google 的库:
- google-api-php-client-1-master
- googleads-adsense-examples-master
有人知道如何手动刷新令牌吗? 谢谢!
【问题讨论】:
-
$client->refreshToken($google_token->refresh_token);然后 $client->getAccessToken() 我认为
-
@DaImTo 什么是 $google_token 变量?谢谢!
-
可能你的 $token[refresh_token] 我的 PHP 有点生锈了抱歉。
-
@DaImTo 谢谢 :) 每个令牌都有一小时的生命周期,我稍后会更新你:)
-
客户端库中有一些东西可以让你在过期时刷新它。如果你让它工作,记得回答你的问题。
标签: php google-api token access-token google-api-php-client