Net::OAuth::Yahoo - Provides simple interface to access Yahoo! APIs
Version 1.0.0
use Net::OAuth::Yahoo; # Construct hashref of OAuth information my $args = { consumer_key => "dj0yJmk9TUhIbnlZa0tYVDAzJmQ9WVdrOWMyMUxNVXBoTjJNbWNHbzlNVGd3TnpjMU5qazJNZy0tJnM9Y29uc3VtZXJzZWNyZXQmeD1lNg--", consumer_secret => "93dfc3e0bbeec0c63b86b6f9f3c55772e4f1fe26", signature_method => "HMAC-SHA1", nonce => "random_string", callback => "oob", }; my $oauth = Net::OAuth::Yahoo->new( $args ); # First, obtain the request token my $request_token = $oauth->get_request_token(); # Second, fetch the OAuth URL to be presented to the user my $url = $oauth->request_auth( $request_token ); # Third, obtain the OAuth Verifier. The real way is to present the $url to the end user, have them click on the "Agree" button, # then obtain the OAuth Verifier. I wrote a simulator subroutine that does this, provided Yahoo ID and password. # If you go with the real way, you can skip this step. my $yid = { login => login, passwd => passwd, }; my $oauth_verifier = $oauth->sim_present_auth( $url, $yid ); # Using the OAuth Verifier, let's get the token. my $token = $oauth->get_token( $oauth_verifier ); # Now it's all done, time to access some API! my $api_url = "http://fantasysports.yahooapis.com/fantasy/v2/team/265.l.5098.t.2/players?format=json"; my $json = $oauth->access_api( $token, $api_url ); OTHER METHODS: The token expires after 1 hour, so you can reuse it until then. 3 methods are provided to facilitate the reuse. # Save the token in a YAML file. $oauth->save_token( "filename" ); # Load the token from a YAML file. my $token = $oauth->load_token( "filename" ); # Test the token against an URL. Returns 1 if good, 0 otherwise. my $ret = $oauth->test_token( $token, $url ); TESTS: Due to the nature of this module, information such as consumer_key, consumer_secret is required. I have provided test_deeply.pl in case the user wants to test the module deeply. This test script prompts for various Net::OAuth information as well as Yahoo login / password. DEBUGGING: This module returns "undef" if something goes wrong. Also, an error message is set in $Net::Oauth::Yahoo::ERRMSG. The user can inspect like so: my $request_token = $oauth->get_request_token(); print $Net::OAuth::Yahoo::ERRMSG if ( !defined $request_token );
This is the constructor. Takes a hashref of the following keys, and returns the Net::OAuth::Yahoo object. my $args = { consumer_key => "dj0yJmk9TUhIbnlZa0tYVDAzJmQ9WVdrOWMyMUxNVXBoTjJNbWNHbzlNVGd3TnpjMU5qazJNZy0tJnM9Y29uc3VtZXJzZWNyZXQmeD1lNg--", consumer_secret => "93dfc3e0bbeec0c63b86b6f9f3c55772e4f1fe26", signature_method => "HMAC-SHA1", nonce => "random_string", callback => "oob", }; my $oauth = Net::OAuth::Yahoo->new( $args );
This method talks to the Yahoo! login server then returns the request_token. No argument is needed as the object contains all the information it needs. my $request_token = $oauth->get_request_token();
Takes the OAuth Verifier (the code that user presents to your webapp) and returns the access token. my $token = $oauth->get_token( $oauth_verifier );
Takes a token and an URL then makes an API call againt the URL. Data from Yahoo API is returned verbatim. This means if you request JSON in the URL, then you'll get JSON back; otherwise XML. my $json = $oauth->access_api( $token, $url );
A private method that abstracts Net::OAuth calls. It is used internally by the object.
A private method that verifies parameters in the constructor.
Takes a request token then returns the URL where the end user needs to access and grant your webapp to access protected resources. my $url = $oauth->request_auth( $request_token );
Takes an URL and hashref of Yahoo login / password information, then simulates the end user's action of granting your webapp to access protected resources. The method returns the OAuth verifier. my $yid = { login => "some_login", passwd => "some_password", } my $oauth_verifier = $oauth->sim_present_auth( $url, $yid );
Takes a filename and dumps the token in YAML format. $oauth->save_token( $file );
Takes a filename and loads token from the file. Returns the token object. my $token = $oauth->load_token( $file );
Takes a token object and URL to try fetching some data. Returns 1 if success, 0 otherwise. This method is useful to see if your loaded token has not expired. my $ret_code = $oauth->test_token( $token );
Simple getter. Returns object attributes if defined, undef otherwise. my $token = $oauth->get( "token" );
Satoshi Yagi, <satoshi.yagi at yahoo.com>
<satoshi.yagi at yahoo.com>
Please report any bugs or feature requests to bug-net-oauth-yahoo at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-OAuth-Yahoo. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-net-oauth-yahoo at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Net::OAuth::Yahoo
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-OAuth-Yahoo
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Net-OAuth-Yahoo
CPAN Ratings
http://cpanratings.perl.org/d/Net-OAuth-Yahoo
Search CPAN
http://search.cpan.org/dist/Net-OAuth-Yahoo/
Copyright 2012 Satoshi Yagi.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install Net::OAuth::Yahoo, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::OAuth::Yahoo
CPAN shell
perl -MCPAN -e shell install Net::OAuth::Yahoo
For more information on module installation, please visit the detailed CPAN module installation guide.