Goodreads Developers discussion

29 views
bugs > author/list is returning wrong start/end data

Comments Showing 1-4 of 4 (4 new)    post a comment »
dateUp arrow    newest »

message 1: by Mosdl (new)

Mosdl | 14 comments So for Terry Pratchett:

http://www.goodreads.com/author/list/...

returns:


however, it only returns 50 books back.


message 2: by Justin (new)

Justin Ray | 11 comments This is probably the same issue I had in this post.

If it helps, here's the code in my app that addresses the issue. It's PHP, but pretty straightforward to translate to another language. In the comments, I note that the function call "$this->getBookReviews" does caching internally, and I just want to stress that the caching is essential to making this approach work without TOS violations.

Best of luck,
Justin


//$page is the the page number, $perpage is the number of books per page
public function getReviews($isbn, $page=1, $perpage=10, $rating=0, $leading=0) {
$reviews = array();
$masterpage = 1;
//loop until we find enough reviews to meet the requested criteria
do {
//first get reviews from the Goodreads API
//this function caches results, so repeated calls with the same parameters
//will not result in repeated API calls. It also rate limits calls to avoid
//API TOS violations
//100 reviews is the max that the Goodreads API will return,
//so always request that many
$data = $this->getBookReviews($isbn, $rating, $masterpage, 100); //always get 100 reviews to save on API calls
if (!isset($firstdata))
$firstdata = $data;
$rawreviews = GoodreadsParser::asArray($data->book->reviews->review);
//this section of code filters out reviews with an empty body (sometimes
//the reviews have a star rating only
$foundmore = false;
foreach ($rawreviews as $rawreview) {
if (strlen(trim($rawreview->body->value)) > 0) {
array_push($reviews, $rawreview);
$foundmore = true;
}
}
$reviewcount = count($reviews);
//increment the internal page counter for the loop
$masterpage++;
//foundmore breaks the loop when the end of the reviews has been reached
//also break the loop when the requested number of reveiws have been
//obtained
} while ($foundmore && $reviewcount < $perpage * $page);
... (more filtering code before returning the reviews)



message 3: by Michael (new)

Michael Economy (michaeleconomy) That page is really weird because its joining together two lists. Books where the author is the primary author, and books where they are the secondary authors.


message 4: by Mosdl (new)

Mosdl | 14 comments Michael wrote: "That page is really weird because its joining together two lists. Books where the author is the primary author, and books where they are the secondary authors."

I noticed :)


back to top