Goodreads Developers discussion

117 views
bugs > API Shelf Name

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

message 1: by Amanda (last edited Jan 22, 2013 12:04PM) (new)

Amanda | 5 comments I apologize if this content was duplicated elsewhere. I searched and couldn't find my question exactly. I had written support an email, but got this response "I’m so sorry to hear you’re experiencing problems with that API method. The best place to post questions about API issues or possible bugs is actually our Official Developers Group. Our engineers monitor the threads very closely, and can help you get it working."

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


message 2: by Michael (new)

Michael Economy (michaeleconomy) I'm not sure i understand, you're passing us a shelf name with a space? Or we're passing you a shelf name with a space?


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


message 3: by Amanda (new)

Amanda | 5 comments I apologize for the confusion. The xml file generated by GoodReads is giving me the space in the tag - under "shelves" it reads "shelf name='to-read'" instead of "shelf_name='to-read'". I'd like to pull the XML for the books in our account so I can add them to our website. I want to add different shelves items to different places and am writing some script to do so. The url I am using for the dump is http://www.goodreads.com/review/list/...? with my key and ID added to the end.


message 4: by Robert (new)

Robert (lathanh) | 14 comments Hi Amanda,

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.



message 5: by Amanda (new)

Amanda | 5 comments So if it calls the tag this way:

foreach($xml->reviews->review As $book)....etc.....

echo 'On Shelf: ' . $book->shelves->shelf . '
';

this should return the shelf name the book is on?


message 6: by Michael (new)

Michael Economy (michaeleconomy) That should work. It's worth noting that a book could technically be on multiple shelves, but only one exclusive shelf.


message 7: by Amanda (new)

Amanda | 5 comments Thats the problem though, it doesn't work. There is technically no tag called "shelf", only one called "shelves". Maybe I am thinking through this too much and its simpler than I'm making it, (that happens alot! :) but <shelf name="read" /> is what I'm trying to read. I've tried $book->shelves->shelf.name too but I couldn't get it to work either. :)


message 8: by Michael (new)

Michael Economy (michaeleconomy) $book->shelves[0].name
?


the shelves call might return an array? I don't know php that well though.


message 9: by Robert (new)

Robert (lathanh) | 14 comments Since the name of the shelf is in an attribute, I think you'll want to call "getAttribute('name')" on each shelf node. That might look something like:

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


message 10: by Amanda (last edited Feb 06, 2013 05:44PM) (new)

Amanda | 5 comments I actually ended up figuring this out two ways. I will post them both here in case it might help anyone else out in the future :)

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!!!


message 11: by Michael (new)

Michael Economy (michaeleconomy) Glad to help, thanks for posting your results!


back to top