Google Analytics API V3 - HTTP Error: Unable to connect to the real server (localhost works fine)

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

In short, my script works fine on the local host, but whenever I boot into our production or intermediate environment, it fails.

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

Again, this works fine on localhost, but errors on our production and intermediate servers.

Error:

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 should be due to file_get_contents () file not working properly or zlib compression error.

So I created a simple script for testing ( https://gist.github.com/jonmilsom/7771566cf55e042b4826 ), but it works fine both on the local host and on the stage and production environments .... how can I debug this further?

0
source share
1 answer

For further debugging, you can go to the client API library at /src/Google/IO/Stream.php and find the line

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

You can add messages to this ... for example, 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 a solution, you can go on 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, but I did not find a solution. I got Cloud Storage working by deleting gzip CONST at the top of Stream.php, but Drive still does not work, and I think it should all be connected.

EDIT: take a look at the problem I'm related to, basically you should try disabling gzip in Config.php - this fixed the problems for me.

I found that this problem is related to different versions of PHP between my localhost and my server.

Here I introduced a new number: https://github.com/google/google-api-php-client/issues/78

+2
source

Source: https://habr.com/ru/post/1388999/


All Articles