Search code examples
phpgoogle-apigoogle-api-php-clientgoogle-books

Why is my Google Books API example failing?


I'm using the Google Books php api example and I'm not getting any results of the call.

Here's an example of what I get when I run

examples/simple-query.php

Simple API Access results

It seems be looking up "Henry David Thoreau" but the results, as you can see, come back blank!

I set up and entered my API key as requested, but I don't seem to be getting anything, hmm.

Does anyone know why this is happening?

Thank you in advance!


Solution

  • Apparently the example is outdated, I got some 'undefined index' errors (your PHP installation is probably not showing notices, that's why it's blank).

    You can fix the example source replacing this:

    foreach ($results as $item) {
      echo $item['volumeInfo']['title'], "<br /> \n";
    }
    

    with:

    foreach ($results->getItems() as $item) {
      echo $item->volumeInfo->getTitle(), "<br /> \n";
    }