#!/usr/bin/perl
use strict;
use Yahoo::BBAuth;
# Test the Photos API using BBauth
# Author: Jason Levitt
# 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 => 'ZUPN1wTIxxxxxxxxxxxxxxxEIEJBc_V26',
secret => 'e7b7f0xxxxxxxxxxxxxxxxxxx0a10439',
);
# 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! Photos Using BBauth
';
print 'You have not authorized access to your Yahoo! Photos 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 $url = 'http://photos.yahooapis.com/V3.0/listAlbums?';
my $xml = $bbauth->auth_ws_get_call($url);
if (!$xml) {
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}.'
';
# Alter the XML so that we can display it in the user's browser without it being
# interpreted as HTML markup
my %entities = ( "<"=>"<", ">"=>">", "&"=>"&" );
while (my ($k, $v) = each(%entities)) {
$xml =~ s/$k/$v/g;
}
print '
The web service call appeared to succeed. Here is the XML response showing your Y! Photo Albums:
'.$xml;
}