Tell me more ×
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 all questions one by one ( starting from the latest )

How would i do that ? I cannot go off of question id ( because they dont seem sequential )

May be i can use page or pagesize but i cannot seem to figure out how .

share|improve this question
can you please elaborate on what you are attempting? there may be a better way to accomplish it. – Sky Sanders Aug 20 '10 at 15:01
I am trying to create an "infinite" stream of questions in my clojure program so i can do "(take 5 questions)" – Surya Aug 20 '10 at 15:27

1 Answer

up vote 3 down vote accepted

that depends on what you mean by 'latest'.

do you mean latest created or latest activity?

in either case, if you truly want to fetch questions one at a time use pagesize=1 and increment page for each request.

Please see notes following this direct answer to your question:

http://api.stackoverflow.com/1.0/questions?page=1&pagesize=1&sort=creation

{
  "total": 879963,
  "page": 1,
  "pagesize": 1,
  "questions": [
    {
      "tags": [
        "symfony",
        "widget",
        "backend"
      ],
      "answer_count": 0,
      "favorite_count": 0,
      "question_timeline_url": "/questions/3532035/timeline",
      "question_comments_url": "/questions/3532035/comments",
      "question_answers_url": "/questions/3532035/answers",
      "question_id": 3532035,
      "owner": {
        "user_id": 426462,
        "user_type": "unregistered",
        "display_name": "enigma",
        "reputation": 1,
        "email_hash": "01a90fc7976ab9b51d143a9da42c8153"
      },
      "creation_date": 1282315993,
      "last_activity_date": 1282315993,
      "up_vote_count": 0,
      "down_vote_count": 0,
      "view_count": 0,
      "score": 0,
      "community_owned": false,
      "title": "multi field widget - format in symfony backend"
    }
  ]
}

http://api.stackoverflow.com/1.0/questions?page=2&pagesize=1&sort=creation

{
  "total": 879966,
  "page": 2,
  "pagesize": 1,
  "questions": [
    {
      "tags": [
        "c#",
        "properties",
        "get",
        "set"
      ],
      "answer_count": 0,
      "favorite_count": 1,
      "question_timeline_url": "/questions/3532038/timeline",
      "question_comments_url": "/questions/3532038/comments",
      "question_answers_url": "/questions/3532038/answers",
      "question_id": 3532038,
      "owner": {
        "user_id": 395126,
        "user_type": "registered",
        "display_name": "rmx",
        "reputation": 486,
        "email_hash": "e489b2b84bf5074bf675330343f93a1b"
      },
      "creation_date": 1282316000,
      "last_activity_date": 1282316000,
      "up_vote_count": 1,
      "down_vote_count": 0,
      "view_count": 5,
      "score": 1,
      "community_owned": false,
      "title": "Correct use of C# properties"
    }
  ]
}

NOTES:

Please be sure that fetching single records fits your use case properly. There are subtle issues that you will encounter when paging by 1 on the head of a temporally sorted dataset, especially one as large and active as the so database.

share|improve this answer
perfect!!!. thanks – Surya Aug 20 '10 at 14:59
@surya - my pleasure. if you have any other questions, please do ask. there are many here who are happy to provide many perspectives. – Sky Sanders Aug 20 '10 at 15:03

You must log in to answer this question.

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