#!/usr/bin/perl
# Test the Mail API using BBauth
# Author: Jason Levitt
use strict;
use Yahoo::BBAuth;
use Data::Dumper;
# Display errors in the web browser, if possible
use CGI::Carp qw(fatalsToBrowser);
# Make sure standard output headers are sent
use CGI qw(:all);
print header();
# Put your BBauth appid and secret here
my $bbauth = Yahoo::BBAuth->new(
appid => 'Mai6nmbxxxxxxxxxxxxxxxxxVXmhAWSrMXr',
secret => '2f8c085baxxxxxxxxxxxxxxxxxxx0c25501f',
);
# Retrieve CGI environment variables
my $grabcgi = CGI->new;
# If the token is not in the environment, we're not coming back from a BBauth authorization
if (!defined($grabcgi->param('token'))) {
my $send_userhash = 1;
my $appdata = 'someappdata';
# Display the BBauth login link for the user
print '
Test Yahoo! Mail API Using BBauth
';
print 'You have not authorized access to your Yahoo! Mail account yet.
';
printf 'Click here to authorize', $bbauth->auth_url(
send_userhash => '1',
appdata => 'someappdata',
);
} else {
# Validate the BBauth attempt
if (!$bbauth->validate_sig()) {
print 'Authentication Failed. Error is:
'.$bbauth->{sig_validation_error};
exit(0);
}
print 'BBauthAuthentication Successful
';
print 'Userhash is: '.$bbauth->{userhash}.'
';
print 'appdata is: '.$bbauth->{appdata}.'
';
# Make an authenticated web services call
my $json = $bbauth->make_jsonrpc_call('ListFolders', [{}] );
if (!$json) {
print 'Web services call failed. Error is:
'. $bbauth->{access_credentials_error};
exit(0);
}
print 'timeout is: '.$bbauth->{timeout}.'
';
print 'token is: '.$bbauth->{token}.'
';
print 'WSSID is: '.$bbauth->{WSSID}.'
';
print 'Cookie is: '.$bbauth->{cookie}.'
';
print '
The JSON-RPC call appeared to succeed. Here is a Perl data structure showing the output of the ListFolders method:
';
print Dumper($json);
}