0

If I retrieve a question like so:

http://api.stackoverflow.com/0.8/questions/1429951&sort=votes

I expect the answers to be sorted by votes, but they're not.

How can I do this?

1 Answer 1

1

I believe the sort=votes parameter is for when you are retrieving multiple questions in one API call, such as with this URL - the questions in the response are ordered by vote.

http://api.stackoverflow.com/0.8/questions/1429951;2383701;619895?sort=votes&type=jsontext

In terms of how you could sort the responses - you do have the up + the down vote count from which you could sort on your application side, or you could make another request to the api with the extracted answer IDs and sort=votes, which is really a waste of resources when you already have all the data.

4
  • Hmmm... I never thought of sorting on the application side. I'll look into that. Commented May 29, 2010 at 21:10
  • @George - OR you could take the questions/{id}/answers route and specify sort. sort on /questions/{id} applies to the question(s) returned. {id} is vectorized in both cases (in all cases, infact). Commented May 30, 2010 at 5:23
  • @Kevin: Oh, okay. I just thought it was wasteful to fetch the question and then all the answers. I guess it won't hurt if the first request has body=false set. Commented May 30, 2010 at 5:45
  • @George - /questions/{id} only gives you the first "page" of answers anyway. If its the full set of answers (by answer_count) you should do the sort locally. Otherwise a second request is necessary anyway, might as well have the sorting done on our end. Commented May 30, 2010 at 6:24

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.