Goodreads Developers discussion
bugs
>
API Shelf Name
date
newest »


Goodreads isn't supposed to support spaces in shelf names currently.


Are you referring to the '/GoodreadsResponse/reviews/review/shelves' tag of the /review/list API call?
If so, for each 'shelf' tag of those 'shelves' tags: the name of the shelf is not in the value of the tag (what appears between the opening tag and the closing tag), but in an attribute* named 'name'.
For example, to get the shelf name from this:
<shelf name="read" />
you need to request the value of the "read" attribute from the 'shelf' tag parser.
* This is similar to an HTML anchor ('a') tag where the 'href' is an attribute while the 'a'-tag's value is the text shown for the link.

foreach($xml->reviews->review As $book)....etc.....
echo 'On Shelf: ' . $book->shelves->shelf . '
';
this should return the shelf name the book is on?



foreach ($review->shelves as $shelf) {
echo 'On Shelf: ' . $shelf->getAttribute('name');
}

Using a form of your recommendations, I figured out how to grab the specific books I wanted via php array like this:
foreach($xml->reviews->review As $book).......
$shelf = ($book->shelves->shelf[1]['name']);......(my custom shelf was always listed as the second entry in the array - thus shelf[1]. The read shelf consistently showed up as shelf[0])
I'm not sure how this would have worked for a book placed not only on the read shelf - but also on 2 or more user shelves. I only ever had one user shelf listed aside from the read shelf. [[I suppose I would have created a second variable like $shelf2 = ($book->shelves->shelf[2]['name']); and then said something like if ($shelf=='name of first shelf' && $shelf2=='name of second shelf') then do something...]]
Then I called $shelf=='nameofshelfhere' where I wanted to sort by the shelf.
This ended up a little convoluted and cumbersome, so I changed the structure of the web pages and the way the XML loads. I was able to pull the books one shelf at a time with the api call to:
''http://www.goodreads.com/review/list? format=xml&v=2&id= (id number goes here) &key= (goodreads key goes here) &per_page=20&shelf=(shelf name goes here)''
Thank you both very much for your help figuring this out!!!
My question is this: I am working on some php code using a Goodreads API XML dump. The information outputted includes "shelves" "shelf name" "/shelves". I need to use the shelf name, however, its the only tag that uses a space in its name instead of an underscore. My code won't accept the space. Is there a way to get the api updated with the correct tag name? I'm sure I'm not the only one with this problem." ( I had included the XML dump link - I can email the link to you if you'd like to see what I'm speaking of.
I'd appreciate any help you might be able to offer.
Amanda