php - 谷歌 api 分析 : error listManagementAccounts in HelloAnalytics. php

标签 php google-analytics google-api google-analytics-api

我正在尝试使用此代码

<?php


error_reporting(E_ALL);
ini_set("display_errors", 1);
// Load the Google API PHP Client Library.
require_once __DIR__ . '/vendor/autoload.php';

$analytics = initializeAnalytics();



 $profile = getFirstProfileId($analytics);
/*$results = getResults($analytics, $profile);
printResults($results);*/

function initializeAnalytics()
{
  // Creates and returns the Analytics Reporting service object.

  // Use the developers console and download your service account
  // credentials in JSON format. Place them in this directory or
  // change the key file location if necessary.
  $KEY_FILE_LOCATION = __DIR__ . '/service-account-credentials.json';

  // Create and configure a new client object.
  $client = new Google_Client();
  $client->setApplicationName("Hello Analytics Reporting");
  $client->setAuthConfig($KEY_FILE_LOCATION);
  $client->setScopes(['https://www.googleapis.com/auth/analytics.readonly']);
  $analytics = new Google_Service_Analytics($client);

  return $analytics;
}

 function getFirstProfileId($analytics) 
 {
    // Get the user's first view (profile) ID.

    // Get the list of accounts for the authorized user.

    $accounts = $analytics->management_accounts->listManagementAccounts();
.....

但我得到这个错误:

Catchable fatal error: Argument 2 passed to Google\Auth\CredentialsLoader::makeCredentials() must be of the type array, object given, called in /home/julienlakq/new_site/administration/analytics/src/Google/Client.php on line 1052 and defined in /home/julienlakq/new_site/administration/analytics/vendor/google/auth/src/CredentialsLoader.php on line 115



我已按照所有步骤操作:创建了一个 jey,通过 google 创建了一个 json key

https://developers.google.com/analytics/devguides/reporting/core/v3/quickstart/service-php#3_setup_the_sample

有人有这个问题吗?

非常感谢 !

最佳答案

问题解决了。

第一:使用带有 v4 api 的 v3 示例:-s

第二:从 php 5.6 到 php 7

然后一切都很好;-)

关于php - 谷歌 api 分析 : error listManagementAccounts in HelloAnalytics. php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40688987/

相关文章:

oauth-2.0 - POSTMAN、OAuth2 和 Google Directory API

google-api - 如何将 Google OAuth 同意屏幕配置为不显示复选框?

php - 正则表达式 - 匹配到点,但没有最后一个字符

google-analytics - 从Google Analytics(分析)自定义报告中删除总计的百分比,而不会丢失其他数据

java - 让 GoogleAnalytics 在所有 Activity 中发挥作用

android - 适用于 Android 的 ISO 适用于 VirtualBox 的 Google API

php - yii 中的 findAll()

PHP 隐藏/显示带分页的图像

php - 如何从 eBay API 获取自定义标签字段?

c# - 使用 Google Analytics 跟踪文本框条目