OAuth returned token not valid


#1

Hi folks. I’m new to developing with the Twitter API, and I’m running into issues with OAuth.

My program will be command-line, and will end up posting to multiple accounts over its’ lifetime, so I can’t use the single access authentication method. I borrowed the below Perl to try to get the accounts authenticated. The authentication routine works fine - it gives me a URL to visit. The proper account and proper app are mentioned. I authorize the app, get a PIN, and enter it into the app. It kicks back a user ID, the proper name, and an access token and secret.

Problem is, that access token and secret don’t work. The Perl immediately tries to tweet, and it won’t go. I get an error of “Could not authenticate you” from the Perl.

Am I messing up the OAuth routine somehow? Is there any way to manually get an access token and authorize each account on the Web, without having to go programmatic?

Thanks!

#!/usr/bin/perl

use Net::Twitter;
use Scalar::Util 'blessed';

my $tweet = 'Im tweeting from an OAuth PERL app everybody!';

my $twitterconsumer = "CONSUMER";
my $twitterconsumersecret = "CONSUMER SECRET";
my $twitteraccesstoken = "";
my $twitteraccesstokensecret = "";

my $nt = Net::Twitter->new(
        traits          => ['API::REST', 'OAuth'],
        consumer_key    => $twitterconsumer,
        consumer_secret => $twitterconsumersecret,
);

if ($twitteraccesstoken && $twitteraccesstokensecret) {
        $nt->access_token($twitteraccesstoken);
        $nt->access_token_secret($twitteraccesstokensecret);
}

unless ( $nt->authorized ) {
        print "Authorize this app at ", $nt->get_authorization_url, " and enter the PIN#\n";

        my $pin = <>;
        chomp $pin;

        my($access_token, $access_token_secret, $user_id, $screen_name) = $nt->->request_access_token(verifier => $pin);
        print 'Access token: '.$access_token."\r\n".'Access Token Secret: '.$access_token_secret."\r\n";
        print "User ID: $user_id\r\nScreen Name: $screen_name\r\n"; 
        $nt->access_token($access_token);
        $nt->access_token_secret($access_token_secret);
}

$nt->update({ status => $tweet });

The issue is, the returned