1#!/usr/local/bin/perl 2 3# Test the Mail API using BBauth 4# Author: Jason Levitt 5 6use strict; 7use Yahoo::BBAuth; 8use Data::Dumper; 9 10# Display errors in the web browser, if possible 11use CGI::Carp qw(fatalsToBrowser); 12 13# Make sure standard output headers are sent 14use CGI qw(:all); 15print header(); 16 17# Put your BBauth appid and secret here 18my $bbauth = Yahoo::BBAuth->new( 19 appid => 'Mai6nmbxxxxxxxxxxxxxxxxxVXmhAWSrMXr', 20 secret => '2f8c085baxxxxxxxxxxxxxxxxxxx0c25501f', 21); 22 23# Retrieve CGI environment variables 24my $grabcgi = CGI->new; 25 26# If the token is not in the environment, we're not coming back from a BBauth authorization 27if (!defined($grabcgi->param('token'))) { 28 my $send_userhash = 1; 29 my $appdata = 'someappdata'; 30 # Display the BBauth login link for the user 31 print '<h1>Test Yahoo! Mail API Using BBauth</h1>'; 32 print '<b>You have not authorized access to your Yahoo! Mail account yet.</b><br>'; 33 printf '<a href="%s">Click here to authorize</a>', $bbauth->auth_url( 34 send_userhash => '1', 35 appdata => 'someappdata', 36 ); 37} else { 38 39 # Validate the BBauth attempt 40 if (!$bbauth->validate_sig()) { 41 print '<h2>Authentication Failed. Error is: </h2>'.$bbauth->{sig_validation_error}; 42 exit(0); 43 } 44 45 print '<h2>BBauthAuthentication Successful</h2>'; 46 print '<strong>Userhash is: '.$bbauth->{userhash}.'</strong><br>'; 47 print '<strong>appdata is: '.$bbauth->{appdata}.'</strong><br>'; 48 49 # Make an authenticated web services call 50 51 my $json = $bbauth->make_jsonrpc_call('ListFolders', [{}] ); 52 53 if (!$json) { 54 print '<h2>Web services call failed. Error is:</h2> '. $bbauth->{access_credentials_error}; 55 exit(0); 56 } 57 58 print '<b>timeout is: '.$bbauth->{timeout}.'<br>'; 59 print 'token is: '.$bbauth->{token}.'<br>'; 60 print 'WSSID is: '.$bbauth->{WSSID}.'<br>'; 61 print 'Cookie is: '.$bbauth->{cookie}.'<br></b>'; 62 63 print '<br><b>The JSON-RPC call appeared to succeed. Here is a Perl data structure showing the output of the ListFolders method:</b><br><br> '; 64 print Dumper($json); 65} 66 67