2

I want to fetch only my accepted answers from Stack Overflow using the API 2.1 and currently I've following code

$data = file_get_contents("http://api.stackexchange.com/2.1/users/741747/answers?page=1&pagesize=10&order=desc&min=1&sort=votes&site=stackoverflow&filter=!4.nQbW4zw_OOSDSf7");

The above code returns all answers, but I want to filter to only accepted answers.
Searched the API documentation but didn't find anything or maybe I don't know where to look for it.

I Appreciate any kind of advice.

1 Answer 1

2

The API filters are kept pretty simple, and there is no way to restrict these answers to just accepted answers. Your app would loop through the items array and return/handle only those where is_accepted is true.


Since you appear to be using PHP, the Stack.PHP library may save you time and effort, overall.

4
  • Thanks! I'm aware of is_accepted but thought there is another way to do it. If I do it in the way you advised then, suppose, for example, I'm fetching 10 answers at a time (pagination) and if one or more answers are not accepted then I've to exclude those from my result and in this case I'm not able to show 10 answers, so what could be the work around, any ideas ?
    – The Alpha
    Mar 11, 2013 at 0:30
  • I'm not a big PHP coder, but I edited the answer to point to a library that appears to help with this kind of thing. Mar 11, 2013 at 0:31
  • If I have (I don't have now) 5000 answers then how much time it could take to fetch all of them using a single request you think, is this a good idea ?
    – The Alpha
    Mar 11, 2013 at 0:47
  • Requests are limited to 100 results at a time, so 5000 answers would take 50 requests. Based on my apps, I'm guessing that would take 10 to 60 seconds, but you'd probably only have to do it every few hours, if that. Mar 11, 2013 at 0:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .