我已经尝试过官方的HelloAnalytics教程,但是它不起作用。
我收到了这个错误:
"PHP致命错误:未找到类'Google_Auth_AssertionCredentials‘’“
我的代码:
// 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);
}更新:
在添加建议的V1主分支后,我现在得到以下错误
googleapis.com/analytics/v3/management/accounts:(403)用户没有任何Google帐户。
发布于 2016-04-06 10:41:10
问题nr 1:
如果不使用composer,请确保下载了v1-主分支- 链接。
问题nr 2:
(403)用户没有任何帐户。
默认情况下,您使用的是服务帐户,服务帐户无法访问任何google分析帐户。您需要从Google开发人员控制台获取服务帐户电子邮件地址,并将其添加为帐户级别的用户,这必须是管理部分下的Google网站中的帐户级别。
发布于 2016-04-06 08:41:41
针对您的问题,您需要在php 'include_path‘中添加库的基本目录。
尝试将这一行代码放在require_once之前
set_include_path( get_include_path() . PATH_SEPARATOR . 'vendor/google/src' );https://stackoverflow.com/questions/36445746
复制相似问题