2

I'm trying to fetch questions one by one, starting from the latest, so that I can create an infinite stream of questions in a Clojure program. I haven't yet been able to do so.

I can't just get the latest question ID and go backwards, because they don't seem sequential. It might be possible with page and pagesize, but I can't figure out how.

2
  • can you please elaborate on what you are attempting? there may be a better way to accomplish it. Aug 20, 2010 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, 2010 at 15:27

1 Answer 1

3

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.

1
  • @surya - my pleasure. if you have any other questions, please do ask. there are many here who are happy to provide many perspectives. Aug 20, 2010 at 15:03

You must log in to answer this question.

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