【发布时间】:2013-05-21 11:21:43
【问题描述】:
重要编辑:发现该问题是由我的网络服务器引起的(我不知道如何解决) - 标签已更改。我使用最新的 XAMPP。
我正在尝试按照本指南使用 OAuth 设置与 Google Analytics API 的服务器到服务器连接: Service Applications and Google Analytics API V3: Server-to-server OAuth2 authentication?
我有以下代码:
require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_AnalyticsService.php';
// create client object and set app name
$client = new Google_Client();
$client -> setApplicationName("------------"); // name of your app
// set assertion credentials
$client->setAssertionCredentials(
new Google_AssertionCredentials(
"------------@developer.gserviceaccount.com", // email you added to GA
array('https://www.googleapis.com/auth/analytics.readonly'),
file_get_contents("-:/-----------/-----/------/----/---------------------------------------------------.p12") // keyfile you downloaded
));
// other settings
$client->setClientId("------------.apps.googleusercontent.com"); // from API console
$client->setAccessType('offline_access'); // this may be unnecessary?
// create service and get data
$service = new Google_AnalyticsService($client);
$ids = "ga:--------";
$startDate = "2013-05-01";
$endDate = "2013-05-26";
$metrics = "ga:visitors";
var_dump($service->data_ga->get($ids, $startDate, $endDate, $metrics));
这会导致 HTTP 错误 #101 (ERR_CONNECTION_RESET)。我的问题类似于:Service Applications and Google Analytics API V3: Error 101 (net::ERR_CONNECTION_RESET),但我没有其他电话给Google_AnalyticsService()。
我有启用 OpenSSL 的 PHP 5.4.7(XAMPP 版本)(通过 php.ini 中的取消注释行启用)。
提前感谢您的任何回答。如何处理这样的问题(产生一些 HTTP 错误并停止?是否有日志产生任何有用的信息?)?
编辑:从帖子中复制代码:"Not sufficient permissions" google analytics API service account 给我会导致同样的错误(没有打印其他消息)。
【问题讨论】:
标签: php apache xampp google-api-php-client