Google Analytics(分析)服务API(ERR_CONNECTION_RESET) [英] Google Analytics service API (ERR_CONNECTION_RESET)

查看:202
本文介绍了Google Analytics(分析)服务API(ERR_CONNECTION_RESET)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

重要发现该问题是由我的Web服务器引起的(我不知道如何解决)-标记已更改.我使用最新的XAMPP.

IMPORTANT Found out that issue is caused by my web server (I don't know how to fix that) - tags changed. I use latest XAMPP.

我正在尝试按照本指南使用OAuth将服务器与Google Analytics(分析)API建立服务器到服务器的连接: 服务应用程序和Google Analytics API V3:服务器到服务器的OAuth2身份验证?

I am trying to set up server to server connection with Google Analytics API with OAuth following this guide: 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)的原因.我的问题类似于:服务应用程序和Google Analytics API V3:错误101(net :: ERR_CONNECTION_RESET),但我没有对Google_AnalyticsService()的其他调用.

Which causes HTTP error #101 (ERR_CONNECTION_RESET). My issue is similar to: Service Applications and Google Analytics API V3: Error 101 (net::ERR_CONNECTION_RESET) but I have no other calls to Google_AnalyticsService().

我的PHP版本为5.4.7(XAMPP版本),并且启用了OpenSSL(通过php.ini中的逗号分隔线启用).

I have PHP version 5.4.7 (XAMPP version) with enabled OpenSSL (enabled via uncommeting line in php.ini).

在此先感谢您提供任何答案.

Thank you in advance for any answers. How to deal with ones like this (producing some HTTP error and stopping? Are there logs that produce any useful informations?)?

从帖子中复制代码:没有足够的权限"向我发送的Google Analytics(分析)API服务帐户会导致相同的错误(未打印其他消息).

Copying code from post: "Not sufficient permissions" google analytics API service account to me causes same error (no other messages printed).

推荐答案

我找到了解决此问题的方法.这是由Apache和PHP共同引起的-他们使用了不同版本的OpenSSL.

I found way to deal with this issue. It's caused by Apache and PHP together - they use different version of OpenSSL.

  • 在XAMPP 1.8.1(发行日期30.9.2012)上,第一个解决方法(对我来说无效,因为我写了05-28-3013)是替换Apache ssleay32.dll和libeay32.dll. >文件夹,其中包含php文件夹中的内容.它对我不起作用,因为mod_ssl无法与PHP的DLL一起使用.
  • 第二种解决方法是安装其他软件包.就个人而言,我切换到ZendServer,该服务器已同步了OpenSSL和Apache的版本.
  • First workaround (one that does not work for me as I write it 05-28-3013) on XAMPP 1.8.1 (release date 30.9.2012) is to replace files ssleay32.dll and libeay32.dll within Apache /bin/ folder with these from php folder. It does not work for me because mod_ssl can't work with PHP's DLLs.
  • Second workaround is to install other package. Personally, I switched to ZendServer which has synced versions of OpenSSL and Apache.

当然,您始终可以构建自己的Apache和PHP,以确保您具有OpenSSL和mod_ssl的最新版本.

Of course you can always build your own Apache and PHP making sure you have OpenSSL and mod_ssl cooperating and in latest version.

这篇关于Google Analytics(分析)服务API(ERR_CONNECTION_RESET)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆