Problems with the Google API PHP simple-query example -
i trying google simple-query example (off github) working, unfortunately definite lack of success ... exit code of 255.
i established problem in call google server, added exception handler code. program looks this:
<?php /* * copyright 2013 google inc. * * licensed under apache license, version 2.0 (the "license"); * may not use file except in compliance license. * may obtain copy of license @ * * http://www.apache.org/licenses/license-2.0 * * unless required applicable law or agreed in writing, software * distributed under license distributed on "as is" basis, * without warranties or conditions of kind, either express or implied. * see license specific language governing permissions , * limitations under license. */ include_once "templates/base.php"; echo pageheader("simple api access"); /************************************************ make simple api request using key. in example we're not making request specific user, indicating request comes our application, , hence should use our quota, higher anonymous quota (which limited per ip). ************************************************/ set_include_path("../src/" . path_separator . get_include_path()); require_once 'google/client.php'; require_once 'google/service/books.php'; /************************************************ create client , set simple api access key. if comment out call setdeveloperkey, request may still succeed using anonymous quota. ************************************************/ $client = new google_client(); $client->setapplicationname("client_library_examples"); $apikey = "******************************************"; if ($apikey == '<your_api_key>') { echo missingapikeywarning(); } $client->setdeveloperkey($apikey); $service = new google_service_books($client); /************************************************ make call our service, map structure of api. in case $service books api, resource volumes, , method listvolumes. pass required parameters (the query), , array of named optional parameters. ************************************************/ $optparams = array('filter' => 'free-ebooks'); // next line replaced exception handling block // $results = $service->volumes->listvolumes('henry david thoreau', $optparams); try{ $results = $service->volumes->listvolumes('henry david thoreau', $optparams); var_dump($results); } catch (exception $e) { echo "call error: " .$e->getmessage()."\n"; echo $e->gettraceasstring()."\n"; } /************************************************ call returns list of volumes, can iterate on them normal array. calls return single item can use. individual responses typed google_service_books_volume, can treated array. ***********************************************/ echo "<h3>results of call:</h3>"; // update code (off stackoverflow) //foreach ($results $item) { // echo $item['volumeinfo']['title'], "<br /> \n"; //} foreach($results->getitems() $item){ echo $item->volumeinfo->gettitle(), "<br /> \n"; } /************************************************ example of deferring call. ***********************************************/ //$client->setdefer(true); //$optparams = array('filter' => 'free-ebooks'); //$request = $service->volumes->listvolumes('henry david thoreau', $optparams); //$results = $client->execute($request); // //echo "<h3>results of deferred call:</h3>"; //foreach ($results $item) { // echo $item['volumeinfo']['title'], "<br /> \n"; //} // echo pagefooter(__file__);
the error trace follows:
call error: http error: unable connect: '0' #0 c:\srv\googleapi\google\io\abstract.php(117): google_io_stream->executerequest(object(google_http_request)) #1 c:\srv\googleapi\google\http\rest.php(42): google_io_abstract->makerequest(object(google_http_request)) #2 c:\srv\googleapi\google\client.php(499): google_http_rest::execute(object(google_client), object(google_http_request)) #3 c:\srv\googleapi\google\service\resource.php(195): google_client->execute(object(google_http_request)) #4 c:\srv\googleapi\google\service\books.php(2304): google_service_resource->call('list', array, 'google_service_...') #5 c:\srv\googleapi\simple-query.php(60): google_service_books_volumes_resource->listvolumes('henry david tho...', array) #6 {main} <h3>results of call:</h3> process finished exit code 255
any assistance appreciated.
nb: possible authentication issue. remote worker without access google console, must rely on boss swears has provided correct key !
i in fact rowanrh on github. after posting above - , not having received assistance - decided duplicate post on github.
i have resolved issue changing following php.ini settings:
- i set (by uncommenting) extension=php_openssl.dll - necessary 'https' urls; ,
- i set time-zone. google fussy times, might have affected outcome.
after testing in ide (i use phpstorm) restarted apache , !!
Comments
Post a Comment