Keith
Keith

Reputation: 4204

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!

Upvotes: 0

Views: 361

Answers (1)

Vinicius Braz Pinto
Vinicius Braz Pinto

Reputation: 8289

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

Upvotes: 1

Related Questions