谷歌分析API V3 - HTTP错误:无法连接在实时服务器上(本地工作正常) [英] Google Analytics API V3 - HTTP Error: Unable to connect on live server (localhost works fine)

查看:153
本文介绍了谷歌分析API V3 - HTTP错误:无法连接在实时服务器上(本地工作正常)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(我正在使用此库的最新版本: https://github.com简单地说,我的脚本在本地主机上完美工作,但每当我上传到我们的生产环境或临时环境时它失败了。



我现在使用本教程中一个非常简单的测试脚本: http://blog.salteh.net/2012/10/google-analytics-api-and-service-accounts/



同样,这对localhost非常有用,但是在我们的生产服务器和登台服务器上出错。
$ b 错误是:

  HTTP错误:无法连接

从我们的错误日志中,我们得到:

  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_cont (compress.zlib:\ / \ / https:\ / \ / accounts.google.com \ / o\ / oauth2\ / token):无法打开流:操作失败} php_error 

我相信这一定是由于file_get_contents()无法正常工作或zlib压缩出错。



因此,我创建了一个简单的脚本来测试( https://gist.github.com/jonmilsom/7771566cf55e042b4826 ),但是在localhost和分段&生产环境....如何进一步调试?

解决方案

要进一步调试,您可以访问API客户端库/src/Google/IO/Stream.php,然后查找

 这一行,并抛出新的Google_IO_Exception(HTTP Error:Unable连接); 

您可以将消息附加到...以获取http错误代码

 抛出新的Google_IO_Exception(HTTP Error:Unable to connect。$ this-> getHttpResponseCode($ http_response_header)); 

如果您想出任何解决方案,请告知我们您可能需要遵循以下问题: https://github.com/google/google-api-php-client/issues / 75 。我的代码在我的本地主机上工作正常,但不在我的开发服务器上,但我还没有想出一个解决方案。我通过删除Stream.php顶部的gzip CONST来运行Cloud Storage,但Drive仍然不起作用,我认为这一切都必须相关。



编辑:看看我链接的问题,基本上你应该尝试在Config.php中设置禁用的gzip - 这解决了我的问题。



I发现这个问题与我的本地主机和我的服务器之间的PHP版本不同有关。我在这里提交了一个新问题:

https://github.com/google/google-api-php-client/issues/78

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

解决方案

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

这篇关于谷歌分析API V3 - HTTP错误:无法连接在实时服务器上(本地工作正常)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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