Question

I am trying to connect to the google API from a localhost, but keep on receiving an exception (key changed - in text below).

Warning: file_get_contents(compress.zlib://https://www.googleapis.com/books/v1/volumes?q=Henry+David+Thoreau&filter=free-ebooks&key=bItatTTTTT7amAHYSaROTTTTTbtttuuuuuuuu) [function.file-get-contents]: failed to open stream: operation failed in C:\zendProject\zf2\vendor\google\apiclient\src\Google\IO\Stream.php on line 115

The code I am using in my browser comes straight from the API Guide and reads:

$client = new \Google_Client(); 
$client->setApplicationName("rent");
$service = new \Google_Service_Books($client);
$optParams = array('filter' => 'free-ebooks');
$results = $service->volumes->listVolumes('Henry David Thoreau', $optParams);

I think my problems relate to the config file, and that fact I am working off the localhost development server.

'Google_Auth_OAuth2' => array(
      'application_name' => 'www.example.com',
       'client_id' => '4498xxxxx061-3333xxxx9pjcpkbqhoxxxxxxxxxxx.apps.googleusercontent.com',
       'client_secret' => '8xxxxxxxxx333xxxxxxxxx',
       'redirect_uri' => 'http://localhost',
       'developer_key' => 'AxxxxxxzBjpxxxxxaxxxxxxZxxx1xxxxx',

In the new developer console I have created a new client ID for the project and inserted the "Client_id", "Client_secret", etc.

I have also enabled the relevant APIs for Calenders and Books.

I have tested my API key on the URL I found for google fonts - so I am sure I have the right developer key.

I suspect the issue may be around the local host in uri fields, what do I need to put in here?

Does anyone know what I am doing wrong.

UPDATE: I found a post that suggested getting the HTTP response code here:

The response from the server is 304 - not sure if this helps

UPDATE: @Carlos Roubles - was correct I was using the incorrect version. Just in case anyone else runs into this issue - the composer information on the google website appears to be incorrect.

I previously used "google/apiclient": "1.0." this appears in the google documentation. I have now tried "google/apiclient": "1." and this seems to have fixed the problem.

Was it helpful?

Solution

Thats a problem with file_get_contents rather that with the api. Most people changes file_get_contents to CURL for accesing remote files. Anyways, i was checking the library and i cannot find any call to file_get_contents in all the stream.php file

https://github.com/google/google-api-php-client/blob/master/src/Google/IO/Stream.php

and in line 115, what we have is a commented line, so what comes to my mind is that yu are not using the last version of the library. Also, i see that in this version they make the request with fopen. So you can try to update it, and probably this fixes the issue

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top