5

I made a small cron job which crawls questions and answers from Stack Overflow.

Here is my request URL:

https://api.stackexchange.com/2.2/questions?order=desc&tagged=php&site=stackoverflow&filter=withbody&no_expiry=true&pagesize=100&key=[my_app_key]access_token=[my_acc_token]

It returns the 100 latest questions in the PHP tag perfectly. But, I would like to include the answers of the questions too (if it is answered).

I have checked the filters section of documentation but I didn't get it exactly. Can anyone point me to the correct direction?

1 Answer 1

4

The various /questions routes do allow you to simultaneously retrieve answers, if you set the right filter.

A good starting filter for getting questions with answers is: !gB7hjL3lhJ*Cnfe63rh6pAm74J(5qrOZKbL

To Customize a Filter:

  1. Go to the /questions documentation page.

  2. Scroll to the Filter Edit Tool:

    Filter edit tool

  3. Click on the tool and this dropdown appears:

    Filter dropdown

  4. Adjust the filter to return just the fields you want without any cruft:

    1. First type withbody into the text box and hit Enter. This presets many of the fields in a good way.

    2. Then expand the various groups and adjust which fields are checked.
      For example, click on badge_count and then click the unselect all badge_count fields link.

    3. It is recommended that you zero out: badge_count, original_question, related_site, and styling. These are almost always unneeded clutter.

    4. Here is the critical part:
      Expand the question group and check answers.

    5. Expand the other fields and uncheck items you do not want. You probably do not need to check any additional items, except in the .wrapper group.

      Be careful about checking private_info properties. If you do have any of these checked, your API calls will fail unless you also pass a valid access_token.

  5. Click the save button.

  6. If you break the filter, repeat step 4 but enter !gB7hjL3lhJ*Cnfe63rh6pAm74J(5qrOZKbL as the starting point.


Also note that you do not need a key or an access_token for most requests to /questions.
It's only needed if your filter returns one of the few protected properties and, since you are fetching all recent questions, these properties will almost never apply anyway.

2
  • Thank you. It worked (after removing the access_token part) :). Right now it returns 100 questions in a single request. Is it possible to increase it ? Sorry if I am taking this question to next level, just asking. Thanks a lot :)
    – Jithesh Kt
    Commented Sep 1, 2015 at 4:53
  • No. You can only get 100 results at a time. To get more, use paging. See this answer for an example of paging. Commented Sep 1, 2015 at 5:09

You must log in to answer this question.

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