How to Do a Twitter Stream API in Perl
The Twitter API allows programmers to access the functionality of Twitter and use Twitter content in a variety of ways. Developers can create Twitter utilities, desktop applications or tools for handheld devices. Since the Twitter API is open, most Web-scripting languages have support for the API in their language, or available as a module. The Perl programming language has the "Net::Twitter" module, which includes objects to send requests to the Twitter servers and fetch data, such as a user's timeline stream.
Instructions
-
-
1
Register a Twitter app. Navigate your browser to dev.twitter.com, select "Create an App" and log in with your Twitter username and password. Fill out your application information, including the application's name and function, and Twitter will give you log-in credentials for your Perl application.
-
2
Send an authentication request to Twitter in a Perl Script, using the credentials you received from the Twitter application registration:
#!/usr/bin/perl
use Net::Twitter;my $twitter = Net::Twitter->new(legacy => 0);
my $twitter = Net::Twitter->new(
traits => [qw/OAuth API::REST/],
consumer_key => consumerkey,
consumer_secret => consumersecret,
access_token => token,
access_token_secret => tokensecret,
); -
-
3
Get your Twitter stream through the "home_timeline" function:
my $statuses = $nt->home_timeline();
-
1