title: Google Analytics API V3 - HTTP Error: Unable to connect on live server (localhost works fine)
body: <p>(I am using the latest version of this library: <a href="https://github.com/google/google-api-php-client" rel="nofollow">https://github.com/google/google-api-php-client</a>)</p>
  
  <p>In short, my script works perfectly on localhost, but whenever I upload to our production or staging environments it fails.</p>
  
  <p>I am now using a really simple test script from this tutorial: <a href="http://blog.salteh.net/2012/10/google-analytics-api-and-service-accounts/" rel="nofollow">http://blog.salteh.net/2012/10/google-analytics-api-and-service-accounts/</a></p>
  
  <p>Again, this works perfectly on localhost, but errors on our production and staging servers.</p>
  
  <p>The error is:</p>
  
  <pre><code>HTTP Error: Unable to connect
  </code></pre>
  
  <p>From our error log, we get:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>I believe this must be due to either file_get_contents() not working correctly or an error with the zlib compression.</p>
  
  <p>I've therefore created a simple script to test (<a href="https://gist.github.com/jonmilsom/7771566cf55e042b4826" rel="nofollow">https://gist.github.com/jonmilsom/7771566cf55e042b4826</a>) but this works fine on both localhost AND the staging &amp; production environments.... how can I debug this further?</p>