Google Analytics服务API(ERR_CONNECTION_RESET)

时间:2013-05-26 11:57:50

标签: php apache xampp google-api-php-client

重要编辑:发现该问题是由我的网络服务器引起的(我不知道如何解决) - 标签已更改。我使用最新的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中的代码复制到我导致同样的错误(没有打印其他消息)。

1 个答案:

答案 0 :(得分:1)

我找到了处理这个问题的方法。它是由Apache和PHP共同造成的 - 它们使用不同版本的OpenSSL。

  • 在XAMPP 1.8.1(发布日期30.9.2012)上的第一个解决方法(对我来说不起作用,因为我写它05-28-3013)是替换文件ssleay32.dlllibeay32.dll在Apache /bin/文件夹中,这些文件夹来自php文件夹。它对我不起作用,因为mod_ssl不能与PHP的DLL一起使用。
  • 第二种解决方法是安装其他软件包。就个人而言,我切换到ZendServer,它已经同步了OpenSSL和Apache的版本。

当然,您可以随时构建自己的Apache和PHP,确保您拥有OpenSSL和mod_ssl合作以及最新版本。