Goodreads Developers discussion

40 views
questions > Add Book

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

message 1: by Karsten (new)

Karsten (strobaek) | 37 comments I am trying to add a book to a shelf using shelf/add_to_shelf.xml.
I add two parameters: name of shelf and (Goodreads) Id of book. I know I'm authorized as I can do an updates/friends.xml. However, I get the response NotAuthorized.
Suggestions?


message 2: by Louise (new)

Louise | 36 comments Karsten, are you doing POST to shelf/add_to_shelf and is it signed the same way you sign when doing updates/friends?


message 3: by Karsten (new)

Karsten (strobaek) | 37 comments Luise,
Yes, POST and signed the same way.


message 4: by Louise (new)

Louise | 36 comments Karsten, I think this is related to the problem you're having with not being authorized to use auth_user. We're looking into it.


message 5: by Karsten (new)

Karsten (strobaek) | 37 comments I have switched to another OAuth lib which has solved the issues I've had getting the user id. When trying to add a book I now get 404: Not found and not NotAuthorized. Somewhat strange as I call shelf/add_to_shelf.xml with id of book (which I have got from a previous search) and name of shelf e.g. "to-read".


message 6: by Virgilio (new)

Virgilio Pigliucci (virgopro) | 9 comments Hi Karsten, can you post the snippet of the code that is not working for you?


message 7: by Karsten (new)

Karsten (strobaek) | 37 comments Hi,

I set up the resource and the parameters in one method

const string resource = "shelf/add_to_shelf.xml";
var parms = new List
{
new Parms("book_id", Book.Id.ToString(CultureInfo.InvariantCulture)),
new Parms("name", Shelf)
};

goodClient.AddBook(resource, parms, ParseAddBook);

I then call my client.

public void AddBook(string resource, IEnumerable parms, Action action)
{
var pc = new ParameterCollection();
foreach (var p in parms)
{
pc.Add(new Parameter(p.Key, p.Value));
}

var client = new OAuthClient(key, secret, token.AccessToken)
{
MethodType = MethodType.Post,
Url = string.Format("{0}{1}", baseUrl, resource),
Parameters = { pc }
};

client.GetResponseText() // post and GetResponse
.Select(s => XElement.Parse(s))
.ObserveOnDispatcher()
.Subscribe(
x => action(HttpStatusCode.OK, x.ToString()),
ex => MessageBox.Show(ex.ToString()));
}


message 8: by Virgilio (new)

Virgilio Pigliucci (virgopro) | 9 comments I don't see major problems on this code. I tried the API endpoint on my side. Our oauth testing code passes explicitly the format parameter in the POST:

data = {'format'=>'xml',
'book_id' => "#{b.id}",
'name' => "#{shelf.name}"}
post_oauth 'add_to_shelf', data

Can you try that?


message 9: by Karsten (new)

Karsten (strobaek) | 37 comments Tried to add format,xml but that made no difference.

Other ideas?


message 10: by Karsten (new)

Karsten (strobaek) | 37 comments Solved. Turned out I was using the wrong ID. Thanks for your help.


message 11: by Virgilio (new)

Virgilio Pigliucci (virgopro) | 9 comments Oh well, sorry to hear it took so long to figured it out.
Happy coding


back to top