首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Auth Analytics PHP

Auth Analytics PHP
EN

Stack Overflow用户
提问于 2016-04-06 08:36:53
回答 2查看 1.3K关注 0票数 2

我已经尝试过官方的HelloAnalytics教程,但是它不起作用。

我收到了这个错误:

"PHP致命错误:未找到类'Google_Auth_AssertionCredentials‘’“

我的代码:

代码语言:javascript
复制
  // Creates and returns the Analytics service object.

  // Load the Google API PHP Client Library.
   require_once 'vendor/autoload.php';

  // Use the developers console and replace the values with your
  // service account email, and relative location of your key file.
  $service_account_email = 'xxxxxxxxxxx@gmail.com';
   $key_file_location = 'key_anyl.p12';

 // Create and configure a new client object.
  $client = new Google_Client();
  $client->setApplicationName("HelloAnalytics");
   $analytics = new Google_Service_Analytics($client);

 // Read the generated client_secrets.p12 key.
  $key = file_get_contents($key_file_location);
  $cred = new Google_Auth_AssertionCredentials(
  $service_account_email,
  array(Google_Service_Analytics::ANALYTICS_READONLY),
  $key
   );
 $client->setAssertionCredentials($cred);
   if($client->getAuth()->isAccessTokenExpired()) {
   $client->getAuth()->refreshTokenWithAssertion($cred);
  }

更新:

在添加建议的V1主分支后,我现在得到以下错误

googleapis.com/analytics/v3/management/accounts:(403)用户没有任何Google帐户。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-04-06 10:41:10

问题nr 1:

如果不使用composer,请确保下载了v1-主分支- 链接

问题nr 2:

(403)用户没有任何帐户。

默认情况下,您使用的是服务帐户,服务帐户无法访问任何google分析帐户。您需要从Google开发人员控制台获取服务帐户电子邮件地址,并将其添加为帐户级别的用户,这必须是管理部分下的Google网站中的帐户级别。

票数 0
EN

Stack Overflow用户

发布于 2016-04-06 08:41:41

针对您的问题,您需要在php 'include_path‘中添加库的基本目录。

尝试将这一行代码放在require_once之前

代码语言:javascript
复制
set_include_path( get_include_path() . PATH_SEPARATOR . 'vendor/google/src' );
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36445746

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档