Net::Twitter::OAuth - Net::Twitter subclass that uses OAuth instead of Basic Auth


  use Net::Twitter::OAuth;

  my $client = Net::Twitter::OAuth->new(
      consumer_key    => "YOUR-CONSUMER-KEY",
      consumer_secret => "YOUR-CONSUMER-SECRET",

  # You'll save these token and secret in cookie, config file or session database
  my($access_token, $access_token_secret) = restore_tokens();
  if ($access_token && $access_token_secret) {
      $client->oauth_token($access_token, $access_token_secret);

  unless ($client->is_authorized) {
      # The client is not yet authorized: Do it now
      print "Authorize this app at ", $client->oauth_authorize_url, " and hit RET\n";

      <STDIN>; # wait for input

      my($access_token, $access_token_secret) = $client->request_access_token;
      save_tokens($access_token, $access_token_secret); # if necessary

  # Everything's ready: same as Net::Twitter
  my $tweets = $client->friends_timeline;
  my $res    = $client->update({ status => "I CAN HAZ OAUTH!" });


Net::Twitter::OAuth is a Net::Twitter subclass that uses OAuth authentication instead of the default Basic Authentication.

Note that this client only works with APIs that are compatible to OAuth authentication.


  $client = Net::Twitter::OAuth->new(
      consumer_key => $consumer_key,
      consumer_secret => $consumer_secret,

Creates a new Net::Twitter::OAuth object. Takes the parameters consumer_key and consumer_secret that can be acquired at Twitter Developer screen

  $client->oauth_token($access_token, $access_token_secret);

Sets access token and secret, saved in your app's local storage (e.g. config file, cookie or session database). This allows you to calling APIs once the application is authorized by the user.


Returns the state if the app is already authorized to access APIs. If this returns false, you should call oauth_authorize_url etc. to let user authorize the application.

  my $url = $client->oauth_authorize_url;

Returns the URL where the end user is asked to authorize the application.

  my($access_token, $access_token_secret) = $client->request_access_token;

Once the application is authorized by the user, your code should call this method to exchange the generic token to access token for later API calls. You probably want to save these token in a local storage so that you can skip the authorization phase for the next run.


Tatsuhiko Miyagawa <>


This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


Net::Twitter, Net::OAuth::Simple