Posted on 2009-05-14 03:57:20-07 by znmeb
How many Twitter API calls does a method consume??
I've got a pretty simple script here:
#!/usr/bin/perl -w use strict; use Net::Twitter; my $username; my $password; my $friendname; my $handle = Net::Twitter->new({username=>$username, password=>$password}) or die $!; my $rate_limit_status = $handle->rate_limit_status(); my $public_timeline = $handle->public_timeline(); my $friends_ids = $handle->friends_ids({id=>'znmeb'}); my $followers_ids = $handle->followers_ids({id=>'znmeb'});


etc. The $username and $password are stored in 'login.pl'. It looks like these method calls are using anywhere from ten to 25 API calls each. I can only run this script a couple of times before the "rate_limit_status" is showing I have zero calls left. Am I doing something wrong?? I'll post some numbers in about an hour. :)
Direct Responses: 10866 | Write a response
Posted on 2009-06-01 00:12:06-07 by semifor in response to 10704
Re: How many Twitter API calls does a method consume??

$handle->rate_limit_status() is actually reporting the status of your IP address, rather than the authenticated user. When rate_limit_status is called without an authentication header, Twitter returns the rate_limit_status for the IP address. When sent with an authentication header, Twitter returns the rate_limit_status for the authenticated user.

Currently, Net::Twitter never sends an authentication header with any API call, initially. That's basically because of the way LWP::UserAgent works (and because of the HTTP standard). Net::Twitter sends a call without an authentication header. Twitter replies with a 401, and headers indicating authentication is required, and importantly, that it accepts Basic Authentication and the Basic Auth Realm. LWP::UserAgent then sends a new request with the appropriate headers.

Rather than sending a 401 for rate_limit_status, however, Twitter sends a status code 200 and the rate_limit_status for the IP address.

This issue will be addressed shortly.

So, you're getting the rate_limit_status for your IP address. Do you have other twitter applications running for other IDs? Are you behind a firewall where your external IP address (the one Twitter sees) is shared? That might explain the discrepancy.
Direct Responses: Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.