【问题标题】:Google Analytics service API (ERR_CONNECTION_RESET)谷歌分析服务 API (ERR_CONNECTION_RESET)
【发布时间】: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


    【解决方案1】:

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

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

    当然,您始终可以构建自己的 Apache 和 PHP,确保您有 OpenSSL 和 mod_ssl 合作并且是最新版本。

    【讨论】:

    • Soltysik 我遇到了同样的问题,我用我的 XAMPP 1.7.7 围绕 #1 尝试了你的工作,它奏效了。但是请您让我知道这个解决方案的更多背景,因为我看到 Apache DLL 的更新比 PHP DLL 的更新。为什么更新的 DLL 会出现这个问题?
    • @Arfeen 原因可能会有所不同; DLL 文件包含已编译的无头代码。一个 DLL 文件可能包含另一个文件中不存在的代码(例如,函数)。切换它们可能会导致正在使用它们的程序不稳定。
    猜你喜欢
    • 1970-01-01
    • 2013-01-09
    • 2015-09-09
    • 2017-10-10
    • 2019-05-10
    • 1970-01-01
    • 2015-11-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多