Frage

(I am using the latest version of this library: https://github.com/google/google-api-php-client)

In short, my script works perfectly on localhost, but whenever I upload to our production or staging environments it fails.

I am now using a really simple test script from this tutorial: http://blog.salteh.net/2012/10/google-analytics-api-and-service-accounts/

Again, this works perfectly on localhost, but errors on our production and staging servers.

The error is:

HTTP Error: Unable to connect

From our error log, we get:

2014-01-29 10:14:43  /classes/google-api-php-client-read-only/src/Google/IO/Stream.php  115 php_error   {"error_message":"file_get_contents(compress.zlib:\/\/https:\/\/accounts.google.com\/o\/oauth2\/token): failed to open stream: operation failed"}   php_error

I believe this must be due to either file_get_contents() not working correctly or an error with the zlib compression.

I've therefore created a simple script to test (https://gist.github.com/jonmilsom/7771566cf55e042b4826) but this works fine on both localhost AND the staging & production environments.... how can I debug this further?

War es hilfreich?

Lösung

To debug further you can go to the API client library at /src/Google/IO/Stream.php and look for the line that is

throw new Google_IO_Exception("HTTP Error: Unable to connect");

You can append messages on to that... like this to get the http error code

throw new Google_IO_Exception("HTTP Error: Unable to connect " . $this->getHttpResponseCode($http_response_header));

Let me know if you come up with any solution, you may want to follow this issue: https://github.com/google/google-api-php-client/issues/75. My code works fine on my localhost, but not on my dev server as well but I have not figured out a solution. I got Cloud Storage working by removing the gzip CONST at the top of the Stream.php, but Drive still does not work and I am thinking this all has to be related.

EDIT: Take a look at the issue I linked, basically you should try to set gzip to disabled in the Config.php - this fixed the issues for me.

I found this issue had to do with differing PHP versions between my localhost and my server

I submitted a new issue here: https://github.com/google/google-api-php-client/issues/78

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top