News & Interviews
Listen with Audible
Gay and Lesbian
Humor and Comedy
Ask the Author
.Net (Microsoft) GoodReads API example
(showing 1-6 of 6)
post a comment »
Mar 26, 2010 10:40PM
Using the Goodreads API in .Net is a bit verbose but not difficult. This sample method creates a new XML subset from the GoodReads stream. I choose to use XPath but XSLT is another valid option for the XML manipulation.
public XmlDocument GetBookShelf()
string ShelfUrl =
Member ID:].xml?key=[Your Key:]&v=2&shelf=to-read&per_page=64";
HttpWebRequest webRequest =
// Set up a Web Request
webRequest.Accept = "text/xml";
webRequest.Credentials = System.Net.CredentialCache.DefaultCredentials;
webRequest.Method = WebRequestMethods.Http.Get;
// Set up a Web Response
HttpWebResponse xwebResponse = (HttpWebResponse)webRequest.GetResponse();
// Let's stream the XML to an XPath document
Stream responseStream = xwebResponse.GetResponseStream();
XmlTextReader reader = new XmlTextReader(responseStream);
// We are finished with GoodReads - the XML formated data is now in our document.
XPathDocument doc = new XPathDocument(reader);
// Close the stream and close the web response.
// We need a Navigator for out XPath work
XPathNavigator myXPathNavigator = doc.CreateNavigator();
// Move to the 'reviews' node
XPathExpression query = myXPathNavigator.Compile("//reviews");
XPathNavigator node = myXPathNavigator.SelectSingleNode(query);
bool rtrnCde = false;
int intNodeValue = 0;
// Move to the 'end' attrib to get the book count and use it to set up string arrays.
rtrnCde = node.MoveToFirstAttribute();
rtrnCde = node.MoveToNextAttribute();
string strAttrName = node.Name.ToString();
if (strAttrName == "end")
intNodeValue = node.ValueAsInt;
intNodeValue = 1;
// There are a number of ways to query the XML using XPath. This is one easy way.
Books = new string[intNodeValue:];
XPathNodeIterator nodesBook = myXPathNavigator.SelectDescendants("book", "", false);
int cnt = 0;
Books[cnt:] = nodesBook.Current.InnerXml;
[add your own code here to finish whatever you are trying to do - the complete function returns an xmldocument to a WPF XAML script in my code.:]
Mar 29, 2010 09:07AM
Thanks for sharing!
Apr 05, 2010 07:54PM
Afeastman wrote: "Using the Goodreads API in .Net is a bit verbose but not difficult. This sample method creates a new XML subset from the GoodReads stream. I choose to use XPath but XSLT is another valid option f..."
Did you consider using XDocument (System.Xml.Linq)?
Apr 06, 2010 01:00AM
I did but I wanted to use some Regular Expressions in my process and decided to stay with basic C# code. You are correct that Linq is a valid way to handle the XML document received from GoodReads. Sometimes I think we have too many options!
Jul 07, 2010 08:23PM
Building upon this I wrote some tutorials on using OAuth in C# using goodreads as my example.
Hopefully this helps some other C# hackers out there looking to dive into the goodreads API.
Jul 08, 2010 01:45PM
back to top
post a comment »
Add a reference:
Search for a book to add a reference
Flagging a post will send it to the Goodreads Customer Care team for review. We take abuse seriously in our discussion boards. Only flag comments that clearly need our attention. As a general rule we do not censor any content on the site. The only content we will consider removing is spam, slanderous attacks on other members, or extremely offensive content (eg. pornography, pro-Nazi, child abuse, etc). We will not remove any content for bad language alone, or being critical of a particular book.
© 2017 Goodreads Inc
authors & advertisers blog
Welcome back. Just a moment while we sign you in to your Goodreads account.