10

I need to get the question content from StackOverflow site.

I already built the functions that parse the HTML for a question, and return me the question content.

But, I found that there is an API, so I would like to use the API.

http://api.stackoverflow.com/1.1/questions/{id}

doesn't return the content of question.

How can I get it pasing the id {id}?

1 Answer 1

13

First of all, version 1.1 of the API has been deprecated for quite some time now. Users are strongly encouraged to move their applications over to version 2.1.

The URL for retrieving information about a question looks something like this:

http://api.stackexchange.com/2.1/questions/ question_id ?site= site_name

For example, to retrieve information about this very question, one would visit:

http://api.stackexchange.com/2.1/questions/4010?site=stackapps

As you have already noted, this does not include the actual post body. Version 2.0 of the API introduced the concept of filters, which (in your case) requires that you manually specify that you would like to fetch the post body.

Normally you would need to create the filter yourself, but since all you want is the post body, you can use one of the predefined filters: withbody.

Your URL now becomes:

http://api.stackexchange.com/2.1/questions/4010?site=stackapps&filter=withbody

0

You must log in to answer this question.

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