Skip to content

Instantly share code, notes, and snippets.

@Getty
Created November 3, 2010 18:20
Show Gist options
  • Select an option

  • Save Getty/661461 to your computer and use it in GitHub Desktop.

Select an option

Save Getty/661461 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
#
# Net::Twitter - OAuth desktop app example
#
use warnings;
use strict;
use Net::Twitter;
my $consumer_key = shift;
my $consumer_secret = shift;
if (!$consumer_key or !$consumer_secret) {
print "\nUsage: ".$0." consumer_key consumer_secret\n\n";
exit 1;
}
my %consumer_tokens = (
consumer_key => $consumer_key,
consumer_secret => $consumer_secret,
);
my $nt = Net::Twitter->new(traits => [qw/API::REST OAuth/], %consumer_tokens);
my $auth_url = $nt->get_authorization_url;
print "Authorize this application at: $auth_url\nThen, enter the PIN# provided to continue: ";
my $pin = <STDIN>; # wait for input
chomp $pin;
my @access_tokens = $nt->request_access_token(verifier => $pin);
if (@access_tokens) {
print "Access Token : ".$access_tokens[0]."\n";
print "Access Token Secret : ".$access_tokens[1]."\n";
print "Twitter User ID : ".$access_tokens[2]."\n";
print "Twitter Username : ".$access_tokens[3]."\n";
} else {
print "I dont get any access token :(\n";
}
print "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment