Take the 2-minute tour ×
Stack Apps is a question and answer site for apps, scripts, and development with the Stack Exchange API. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

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.

share|improve this answer
    
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 ? –  Sheikh Heera Mar 11 '13 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. –  Brock Adams Mar 11 '13 at 0:31
    
The library looks promising. I'm accepting the answer as right but if you find any better solution then please update your answer. Thanks :-) –  Sheikh Heera Mar 11 '13 at 0:33
1  
Will do. If it was me, I'd have the app fetch ALL results, then filter to just the accepted answers. Cache that array, and handle paging without any further calls to the API. You could periodically check the total parameter, in conjunction with the user's reputation score, to have a good idea if the cache was stale. –  Brock Adams Mar 11 '13 at 0:42
    
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 ? –  Sheikh Heera Mar 11 '13 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. –  Brock Adams Mar 11 '13 at 0:53
    
Thanks for useful info and your effort :-) –  Sheikh Heera Mar 11 '13 at 0:55
add comment

You must log in to answer this question.

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