簡體   English   中英

Google api analytics:HelloAnalytics.php中的錯誤列表管理帳戶

[英]Google api analytics : error listManagementAccounts in HelloAnalytics.php

我正在嘗試使用此代碼

<?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();
.....

但我得到這個錯誤:

可捕獲的致命錯誤:傳遞給Google \\ Auth \\ CredentialsLoader :: makeCredentials()的參數2必須是類型數組,給定對象,在/home/julienlakq/new_site/administration/analytics/src/Google/Client.php中調用1052,並在第115行的/home/julienlakq/new_site/administration/analytics/vendor/google/auth/src/CredentialsLoader.php中定義

我已經遵循了所有步驟:創建了一個jey,通過谷歌創建了一個json密鑰

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

有人有這個問題嗎?

非常感謝 !

問題解決了。

第一:使用樣本v3與v4 api:-s

第二:從PHP 5.6到php 7

然后一切都很好;-)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM