Fri, 25 Sep 2009

Twitter deprecates “page” parameter

If you’re using the Perl Net::Twitter module to access the Twitter API’s friends, followers, friends_ids, or followers_ids methods, you’ll need to switch from using the page parameter to using the cursor parameter before 26-Oct-2009.

Here’s how.

Suppose you have paging code, like this:

To use the cursor parameter:

Set the cursor parameter to an intial value of -1. Pass the next_cursor value from the returned data structure on the next call. Repeat until next_cursor is zero.

When the cursor parameter is used with the friends and followers methods, the return value is a HashRef with keys users, next_cursor, and previous_cursor. The value for users is an ArrayRef of users. When the cursor parameter is excluded, the return value is just the ArrayRef of users.

When the cursor parameter is used with the friends_ids and followers_ids methods, the return value is a HashRef with keys ids, next_cursor, and previous_cursor. The value for ids is an ArrayRef of user IDs. When the cursor parameter is excluded, the return value is just the ArrayRef of user IDs.

Twitter claims this new cursor based paging method is more reliable. It returns slightly more complex data structure requiring some changes to your code. It does, however, save one API call when getting all data. With the page parameter, it was necessary to continue calling the API until an empty array was returned. Using cursor, the next_cursor value is zero when the final page is returned.

Twitter plans to silently drop the page parameter beginning 26-Oct-2009. So, update your code soon to avoid unexpected problems.

[/perl] [link]

About this weblog

This site is the personal weblog of Marc Mims. You can contact Marc by sending e-mail to:
[email protected].

Marc writes here about cycling, programming, Linux, and other items of personal interest.

This site is syndicated with RSS.

Archives

Credits

CSS stolen from Tom Coates who didn't even complain.