Created
June 18, 2010 21:26
-
-
Save semifor/444247 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/user/bin/env perl | |
| # HOWTO - Net::Twitter with OAuth in perl scripts | |
| # | |
| # Register an OAuth app with twitter: | |
| # http://dev.twitter.com/apps | |
| # | |
| # Note the consumer key and consumer secret. | |
| # | |
| # On your app page, select "My Access Token" | |
| # | |
| # Note the access token and secret | |
| # | |
| # create 2 .netrc entries: | |
| # | |
| ## file: $HOME/.netrc | |
| # machine my-scripts.oauth.twitter | |
| # login consumer-key-goes-here | |
| # password consumer-secret-goes-here | |
| # | |
| # machine fred.my-scripts.oauth.twitter | |
| # login access-token-goes-here | |
| # password access-token-secret-goes-here | |
| # | |
| # then in your scripts | |
| # | |
| use warnings; | |
| use strict; | |
| use Net::Netrc; | |
| use Net::Twitter; | |
| my ( $key, $secret ) = Net::Netrc->lookup('my-scripts.oauth.twitter')->lpa; | |
| my ( $token, $token_secret ) = Net::Netrc->lookup('fred.my-scripts.oauth.twitter')->lpa; | |
| my $nt = Net::Netrc->new( | |
| traits => [qw/API::REST OAuth/], | |
| consumer_key => $key, | |
| consumer_secrent => $secret, | |
| access_token => $token, | |
| access_token_secret => $token_secret, | |
| ); | |
| # proceed as before (with the Basic Auth version) | |
| # ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment