Tatsuhiko Miyagawa > Net-Twitter-OAuth-0.02 > Net::Twitter::OAuth

Download:
Net-Twitter-OAuth-0.02.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Module Version: 0.02   Source   Latest Release: Net-Twitter-OAuth-0.06

NAME ^

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

SYNOPSIS ^

  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!" });

DESCRIPTION ^

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.

METHODS ^

new
  $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 http://twitter.com/oauth_clients.

oauth_token
  $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.

is_authorized
  $client->is_authorized;

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.

oauth_authorize_url
  my $url = $client->oauth_authorize_url;

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

request_access_token
  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.

AUTHOR ^

Tatsuhiko Miyagawa <miyagawa@bulknews.net>

LICENSE ^

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

SEE ALSO ^

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

syntax highlighting: