0

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

Community
  • 1
  • 1

1 Answers1

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.

  • Soltysik I had the same problem and I tried your work around # 1 with my XAMPP 1.7.7 and it worked. But would you please let me know the more background of this solution since I see that Apache DLLs were updated then that of PHP DLLs. Why this problem is coming with updated DLLs ? – Arfeen Jun 02 '15 at 12:25
  • 1
    @Arfeen Reasons may vary; DLL file contains already compiled, headless code. One DLL file may contain code (for example, function) that is not present in another one. Switching them may lead to instability of programs that are using them. – Kamil Sołtysik Jun 09 '15 at 01:45