Google Analytics service API (ERR_CONNECTION_RESET)

帅比萌擦擦* 提交于 2019-12-10 12:00:30

问题


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

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?

I have following code:

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));

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().

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?)?

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


回答1:


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

  • 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.

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



来源:https://stackoverflow.com/questions/16758999/google-analytics-service-api-err-connection-reset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!