Net::T...gToV1_1(3pm)
π Net::Twitter::Manual::MigratingToV1_1 π
okay bestie, gather round, because this is the glow-up guide: it's the Net::Twitter::Manual::MigratingToV1_1 page from the perl 3pm manual crew, and it's here to walk you through moving from Twitter API v1 to v1.1 without losing your mind. no cap. β¨
πΈ VERSION πΈ
version 4.01043 β that's the one, that's the era. π
β¨ SYNOPSIS β¨
the vibe, in code form:
use Net::Twitter
my $nt = Net::Twitter->new(
traits => [qw/API::RESTv1_1/],
consumer_key => $consumer_key,
consumer_secret => $consumer_secret,
access_token => $access_token,
access_token_secret => $access_token_secret,
);
look at that. four credentials, one trait, absolutely slaying. π«Ά
π¦ DESCRIPTION π¦
so here's the lore: Net::Twitter before version 4.0 was out here using Twitter API version 1. then Twitter API v1.1 showed up and introduced changes that are not entirely backwards compatible, which means your calling code needs some edits. not a total rewrite, but like, some edits.
Net::Twitter tries to give you backwards compatibility wherever it possibly can. π this doc is the roadmap: it describes exactly what changes your existing application code (the stuff using Net::Twitter) needs so it works with Twitter's API v1.1.
π FIRST π
Include the API::RESTv1_1 trait
anywhere you create a Net::Twitter object by calling new, swap out the trait API::REST and put API::RESTv1_1 in its place. for most applications, that's literally all that's required. that's it. that's the whole step. iconic. π
π EXCEPTIONS π
Trait RateLimit incompatible with API::RESTv1_1
the RateLimit trait is incompatible with Twitter API v1.1. rate limiting is one of the most extensive changes in v1.1, so buckle up:
- in v1 there were two hourly rate limits: one per IP address for unauthenticated calls, and one per-user/application for authenticated calls.
- in v1.1, all calls must be authenticated, and each API endpoint (i.e., each method) has it's own rate limit.
- and it's not hourly anymore β the new rate limits operate on a 15 minute window.
if your code currently uses the RateLimit role, you'll need to write some custom code to provide equivalent functionality. sorry bestie, DIY era. π
rate_limit_status
the return value for rate_limit_status is entirely different. see Twitter's API rate_limit_status documentation for details:
https://dev.twitter.com/docs/api/1.1/get/application/rate_limit_status
blocking
blocking_ids
friends
followers
with API v1.1, these methods use cursor based paging. if you do not pass a cursor parameter, Twitter assumes cursor => -1. so existing code that expects an arrayref return value must be modified to expect a hashref and dereference the users slot:
# With API v1
my $r = $nt->friends;
my @friends = @$r;
# With API v1.1
my $r = $nt->friends;
my @friends = @{$r->{users}};
the way that @$r became @{$r->{users}}β¦ character development, fr fr. π
search
the search method's semantics and return value are substantially different between Twitter API v1 and v1.1.
- in v1,
searchwas provided by theAPI::Searchtrait. - in v1.1,
searchis included in theAPI::RESTv1_1trait.
so, first: drop API::Search from your calls to new. the API::Search trait is incompatible with API::RESTv1_1. do not try it. π
in v1, Twitter returned a hashref with several keys containing meta data. the actual array of results were contained in the results slot:
# With Twitter API v1
my $nt = Net::Twitter->new(traits => [qw/API::REST API::Search/]);
my $r = $nt->search('perl hacker');
for my $status ( @{$r->{results} ) {
# process each status...
}
in v1.1, Twitter returns a hash with 2 slots: search_metadata and statuses.
# With Twitter API v1.1
my $nt = Net::Twitter->new(traits => [qw/API::RESTv1_1/], %oauth_credentials);
my $r = $nt->search('perl hacker');
for my $status ( @{$r->{statuses} ) {
# process each status...
}
paging through search results works differently in v1.1 too. in v1, Twitter offered a page parameter:
# With Twitter API v1
for ( my $page = 1; $page <= 10; ++$page ) {
my $r = $nt->search({ q => $query, page => $page, rpp => 100 });
last unless @{$r->{results}};
# process a page of results...
}
in v1.1, use max_id and count to get paged results:
# With Twitter API v1.1
for ( my %args = ( q => $query, count => 100 ), my $n = 0; $n < 1000; ) {
my $r = $nt->search({ %args });
last unless @{$r->{statuses}};
$args{max_id} = $r->{statuses}[-1]{id} - 1;
$n += @{$r->{statuses}};
# process a page of results...
}
page and rpp? gone. max_id and count? main character energy now. π
π DEPRECATED METHODS π
some Twitter API v1 methods are just not available in v1.1. moment of silence. π―οΈ
friends_timeline
use home_timeline instead. simple swap, slay.
friendship_exists
relationship_exists
follows
friendship_exists and it's aliases are not supported in API v1.1. use show_friendship instead:
my $r = $nt->show_relationship({
source_screen_name => $user_a,
target_screen_name => $user_b,
});
if ( $r->{relationship}{source}{following} ) {
# $user_a follows $user_b
}
see how it's nested now? {relationship}{source}{following} β she's deep, she's detailed, she ate. π
π SEE ALSO π
ngl this page is a one-stop shop β everything you need is right here in the sections above. no extra reading required, bestie. π§
and that's the whole migration, gorgeous. you just read the perl Net::Twitter::Manual::MigratingToV1_1 page, straight from the User Contributed Perl Documentation, version 4.01043, brought to you by perl v5.34.0 and dated 2022-06-16. go forth and v1.1 responsibly. periodt. πβ¨π
π¦ where this page comes from
- debian bookworm: libnet-twitter-perl 4.01043-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libnet-twitter-perl 4.01043-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libnet-twitter-perl 4.01043-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms