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

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

问题描述

(我使用的是这个库的最新版本:https://github.com/google/google-api-php-client)

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

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

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.

错误是:

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

我认为这一定是由于 file_get_contents() 无法正常工作或 zlib 压缩出错.

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

因此我创建了一个简单的脚本来测试(https://gist.github.com/jonmilsom/7771566cf55e042b4826) 但这在本地主机和登台上都可以正常工作生产环境......我该如何进一步调试?

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?

推荐答案

要进一步调试,您可以转到位于/src/Google/IO/Stream.php 的 API 客户端库并查找

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

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

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

如果您想出任何解决方案,请告诉我,您可能想关注这个问题:https://github.com/google/google-api-php-client/issues/75.我的代码在我的本地主机上运行良好,但在我的开发服务器上也运行良好,但我还没有想出解决方案.我通过删除 Stream.php 顶部的 gzip CONST 使 Cloud Storage 工作,但 Drive 仍然无法工作,我认为这一切都必须相关.

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.

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

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.

我发现这个问题与我的本地主机和我的服务器之间的不同 PHP 版本有关

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

我在这里提交了一个新问题:https://github.com/google/google-api-php-client/issues/78

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

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

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