Google api 分析:HelloAnalytics.php 中的错误 listManagementAccounts
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();
.....
但是我得到这个错误:
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 密钥
有人遇到过这个问题吗?
非常感谢!
问题已解决。
首先:使用 v3 和 v4 的样本 api :-s
第二个:从 php 5.6 到 php 7
然后一切都很好;-)
我正在尝试使用此代码
<?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 密钥有人遇到过这个问题吗?
非常感谢!
问题已解决。
首先:使用 v3 和 v4 的样本 api :-s
第二个:从 php 5.6 到 php 7
然后一切都很好;-)