PHP service 链接google api 读取数据

PHP Fatal error: Uncaught exception ‘Exception’ with message ‘DateTime::__construct(): It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone ‘UTC’ for now, but please set date.timezone to select your timezone.’

php里写个时间
date_default_timezone_set(‘Europe/Zurich’);

PHP Fatal error: Uncaught exception ‘Google_Service_Exception’ with message ‘{
“error”: {
“code”: 403,
“message”: “User does not have any Google Analytics account.”,
“errors”: [
{
"message": "User does not have any Google Analytics account.",
"domain": "global",
"reason": "forbidden"
}
],
“status”: “PERMISSION_DENIED”
}
}
‘ in /www/g/vendor/google/apiclient/src/Google/Http/REST.php:118

User does not have any Google Analytics account.”
说明权限不足
在这里

主要代码例子

https://developers.google.com/analytics/devguides/reporting/core/v4/samples

// Create the DateRange object.
$dateRange = new Google_Service_AnalyticsReporting_DateRange();
$dateRange->setStartDate("2015-06-15");
$dateRange->setEndDate("2015-06-30");
 
// Create the Metrics object.
$sessions = new Google_Service_AnalyticsReporting_Metric();
$sessions->setExpression("ga:sessions");
$sessions->setAlias("sessions");
 
//Create the Dimensions object.
$browser = new Google_Service_AnalyticsReporting_Dimension();
$browser->setName("ga:browser");
 
// Create the ReportRequest object.
$request = new Google_Service_AnalyticsReporting_ReportRequest();
$request->setViewId("XXXX");
$request->setDateRanges($dateRange);
$request->setDimensions(array($browser));
$request->setMetrics(array($sessions));
 
$body = new Google_Service_AnalyticsReporting_GetReportsRequest();
$body->setReportRequests( array( $request) );
return $analyticsreporting->reports->batchGet( $body );


This entry was posted in PHP and tagged , . Bookmark the permalink.
月小升QQ 2651044202, 技术交流QQ群 178491360
首发地址:月小升博客https://java-er.com/blog/php-service-google-api/
无特殊说明,文章均为月小升原创,欢迎转载,转载请注明本文地址,谢谢
您的评论是我写作的动力

2 Responses to PHP service 链接google api 读取数据

  1. 码客 says:

    国内访问一次谷歌API花都残了

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

*

  

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

About Me

静水流深,水滴石穿