dongle2627 2016-04-06 00:36
浏览 55
已采纳

Auth Google Analytics PHP API

I have tried the official HelloAnalytics tutorial however it doesn't work.

I am recieveing this error:

"PHP Fatal error: Class 'Google_Auth_AssertionCredentials' not found"

My Code:

  // 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);
  }

Update:

after adding the suggested V1-master branch I am now getting the following error

Uncaught exception 'Google_Service_Exception' with message 'Error calling GET googleapis.com/analytics/v3/management/accounts: (403) User does not have any Google Analytics account.'

展开全部

  • 写回答

2条回答 默认 最新

  • dongyi1921 2016-04-06 02:41
    关注

    Problem nr 1:

    if your not using composer make sure you downloaded the v1-master branch – Link

    Problem nr 2:

    (403) User does not have any Google Analytics account.

    You are using a service account by default a service account does not have access to any google analytics accounts. You need to take the service account email address from Google Developers console and add it as a user at the ACCOUNT level it must be the ACCOUNT level in the Google Analytics website under the admin section.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 某东JD算法逆向算法
  • ¥15 求GCMS辅导数据分析
  • ¥30 SD中的一段Unet下采样代码其中的resnet是谁跟谁进行残差连接
  • ¥15 Unet采样阶段的res_samples问题
  • ¥60 Python+pygame坦克大战游戏开发实验报告
  • ¥15 R语言regionNames()和demomap()无法选中中文地区的问题
  • ¥15 Open GL ES 的使用
  • ¥15 我如果只想表示节点的结构信息,使用GCN方法不进行训练可以吗
  • ¥15 QT6将音频采样数据转PCM
  • ¥15 下面三个文件分别是OFDM波形的数据,我的思路公式和我写的成像算法代码,有没有人能帮我改一改,如何解决?
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部