Php Google API客户端刷新OAuth2令牌
我使用谷歌API检索分析数据并将其显示在我的网站上。它在一个月内运行良好,但在过去的四天中,我遇到了以下错误:Php Google API客户端刷新OAuth2令牌,php,oauth-2.0,google-analytics-api,Php,Oauth 2.0,Google Analytics Api,我使用谷歌API检索分析数据并将其显示在我的网站上。它在一个月内运行良好,但在过去的四天中,我遇到了以下错误: Error refreshing the OAuth2 token, message: '{ "error" : "invalid_grant" }' 代码如下: <?php require_once ('src/Google/autoload.php'); $client = new Google_Client(); $client->setApplicationNam
Error refreshing the OAuth2 token, message: '{ "error" : "invalid_grant" }'
代码如下:
<?php
require_once ('src/Google/autoload.php');
$client = new Google_Client();
$client->setApplicationName( 'GAFetchData' );
$client->setAssertionCredentials(
new Google_Auth_AssertionCredentials(
// Google client ID email address
'xxxxx-xxxxxxxxxx@developer.gserviceaccount.com',
array('https://www.googleapis.com/auth/analytics.readonly'),
file_get_contents( $Path.'gapii/'.'GAFetchData-xxxxxxxx.p12' )
)
);
$client->setClientId( 'xxxxx-xxxxxxxxxx.apps.googleusercontent.com' );
$client->setAccessType( 'offline_access' );
$analytics = new Google_Service_Analytics( $client );
$analytics_id = 'ga:xxxxxx';
try {
$optParams = array();
$metrics = 'ga:pageviews';
$start_date = '7daysAgo';
$end_date = 'today';
$optParams['dimensions'] = 'ga:pagePath';
$optParams['filters'] = 'ga:pagePath!@=rech;';
$optParams['max-results'] = '10000';
$result = $analytics->data_ga->get( $analytics_id, $start_date, $end_date, $metrics, $optParams);
if( $result->getRows() ) { $items = $result->getRows(); }
}
catch(Exception $e) { echo $e->getMessage();}
?>
问题已解决
这是由服务器的时钟引起的,我只是使用以下命令(在我的例子中是Ubuntu)将其与NTP服务器同步:
您将在中找到时间服务器的列表
希望有帮助 问题解决了
这是由服务器的时钟引起的,我只是使用以下命令(在我的例子中是Ubuntu)将其与NTP服务器同步:
您将在中找到时间服务器的列表
希望有帮助
sudo ntpdate 3.pool.ntp.org