Goodreads Developers discussion
      bugs
      >
    API Shelf Name
    
  
  
					date newest »
						  
						newest »
				
		 newest »
						  
						newest »
				 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?
      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.
 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.
      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.
     Hi Amanda,
      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.
 So if it calls the tag this way:
      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?
 That should work. It's worth noting that a book could technically be on multiple shelves, but only one exclusive shelf.
      That should work. It's worth noting that a book could technically be on multiple shelves, but only one exclusive shelf.
     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. :)
      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. :)
     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:
      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');
}
 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 :)
      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!!!


 
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