[英]Google api analytics : error listManagementAccounts in HelloAnalytics.php
I am trying to use this code 我正在尝试使用此代码
<?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();
.....
But I get this error : 但我得到这个错误:
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
可捕获的致命错误:传递给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中定义
I have followed all the steps : created a jey, created a json key via google 我已经遵循了所有步骤:创建了一个jey,通过谷歌创建了一个json密钥
https://developers.google.com/analytics/devguides/reporting/core/v3/quickstart/service-php#3_setup_the_sample https://developers.google.com/analytics/devguides/reporting/core/v3/quickstart/service-php#3_setup_the_sample
Is anyone had this problem ? 有人有这个问题吗?
Thanks a lot ! 非常感谢 !
Problem solved. 问题解决了。
First : Was using sample for v3 with v4 api :-s 第一:使用样本v3与v4 api:-s
Second : gone form php 5.6 to php 7 第二:从PHP 5.6到php 7
And then all is fine ;-) 然后一切都很好;-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.