1

I have implemented fetching the latest questions with php:

https://api.stackexchange.com/2.2/questions?order=desc&sort=activity&tagged=wordpress&site=stackoverflow&filter=withbody

And then getting the answers for the specific questions id's. All of this process run in an hourly cron.

The problem if an answer was added to a specific question my script doesn't catch it.

How can I fetch the latest questions and answers, and in later requests still "catch" new answers ?

Thanks.

1 Answer 1

1

You are looking at questions only. If you want to pull both questions and answers, you have two options.

Option 1: Two API calls

Using this option, you'll use your existing call to get new questions. You'll also add a call to the /answers end point.

The downside to this is the extra API calls this will generate.

Option 2: Use the /posts endpoint

Utilize the /posts end point to get both questions and answers. This returned both new questions and answers with a single call.

The downside to this is that it will only return fields that are common to both post types.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Andy ! Is there an easy way to get new comments from posts I all ready fetched ? without overload with calls. Because after a short time I will have a alot of questions and go check each one it's a bit killing no ?
You can check up to 100 posts at a time. However, you can only get back 100 results per "page", so if each of those 100 posts has 2 new comments, you'd still have to make at 2 calls to the API - one for the first 100 and one for the second 100. There isn't a way to do this any other way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.