Skip to main content
replaced http://stackapps.com/ with https://stackapps.com/
Source Link

The official rate limits are posted hereposted here.

One thing you mentioned in your post does strike me as a little odd:

"I've been doing a first call with pagesize=0 to determine how many pages there are then running a loop querying each page."

Why the need to fetch an empty page to determine the total? Why not fetch the first page (which contains the total) and then continue from there?

"I'm also interested in looking how any Stack Exchange API frameworks might have already implemented methods to query all pages in such "friendly" ways."

I wrote a PHP wrapper for the APIPHP wrapper for the API that does this in a rather unique way. Instead of exposing pagination to the user (although pagination data can be retrieved if needed), a stream of items is provided:

$site = API::Site('stackapps');
$response = $site->Questions()->Unanswered()->Exec();

// The $response variable takes care of pagination for us.
// We simply call Fetch() over and over until it returns FALSE.

while($item = $response->Fetch())
    // Do something with $item

The Fetch() method automatically retrieves new pages as items are requested. It also takes the rate limit into account, pausing to comply with the limit if necessary.

The official rate limits are posted here.

One thing you mentioned in your post does strike me as a little odd:

"I've been doing a first call with pagesize=0 to determine how many pages there are then running a loop querying each page."

Why the need to fetch an empty page to determine the total? Why not fetch the first page (which contains the total) and then continue from there?

"I'm also interested in looking how any Stack Exchange API frameworks might have already implemented methods to query all pages in such "friendly" ways."

I wrote a PHP wrapper for the API that does this in a rather unique way. Instead of exposing pagination to the user (although pagination data can be retrieved if needed), a stream of items is provided:

$site = API::Site('stackapps');
$response = $site->Questions()->Unanswered()->Exec();

// The $response variable takes care of pagination for us.
// We simply call Fetch() over and over until it returns FALSE.

while($item = $response->Fetch())
    // Do something with $item

The Fetch() method automatically retrieves new pages as items are requested. It also takes the rate limit into account, pausing to comply with the limit if necessary.

The official rate limits are posted here.

One thing you mentioned in your post does strike me as a little odd:

"I've been doing a first call with pagesize=0 to determine how many pages there are then running a loop querying each page."

Why the need to fetch an empty page to determine the total? Why not fetch the first page (which contains the total) and then continue from there?

"I'm also interested in looking how any Stack Exchange API frameworks might have already implemented methods to query all pages in such "friendly" ways."

I wrote a PHP wrapper for the API that does this in a rather unique way. Instead of exposing pagination to the user (although pagination data can be retrieved if needed), a stream of items is provided:

$site = API::Site('stackapps');
$response = $site->Questions()->Unanswered()->Exec();

// The $response variable takes care of pagination for us.
// We simply call Fetch() over and over until it returns FALSE.

while($item = $response->Fetch())
    // Do something with $item

The Fetch() method automatically retrieves new pages as items are requested. It also takes the rate limit into account, pausing to comply with the limit if necessary.

Source Link
Nathan Osman
  • 23.3k
  • 11
  • 61
  • 107

The official rate limits are posted here.

One thing you mentioned in your post does strike me as a little odd:

"I've been doing a first call with pagesize=0 to determine how many pages there are then running a loop querying each page."

Why the need to fetch an empty page to determine the total? Why not fetch the first page (which contains the total) and then continue from there?

"I'm also interested in looking how any Stack Exchange API frameworks might have already implemented methods to query all pages in such "friendly" ways."

I wrote a PHP wrapper for the API that does this in a rather unique way. Instead of exposing pagination to the user (although pagination data can be retrieved if needed), a stream of items is provided:

$site = API::Site('stackapps');
$response = $site->Questions()->Unanswered()->Exec();

// The $response variable takes care of pagination for us.
// We simply call Fetch() over and over until it returns FALSE.

while($item = $response->Fetch())
    // Do something with $item

The Fetch() method automatically retrieves new pages as items are requested. It also takes the rate limit into account, pausing to comply with the limit if necessary.