NAME
WebService::GData::ClientLogin - implements ClientLogin authorization for google data related APIs v2.
VERSION
0.01
SYNOPSIS
#you will want to use a service instead such as WebService::GData::YouTube;
use WebService::GData::Base;
use WebService::GData::ClientLogin;
#create an object that only has read access
my $base = new WebService::GData::Base();
eval {
my $auth = new WebService::GData::ClientLogin(
email => '...',
password => '...',
service => '...', #default to youtube,
source => '...' #default to WebService::GData::ClientLogin-$VERSION,
type => '...' #default to HOSTED_OR_GOOGLE
);
};
if(my $error = $@){
#$error->code,$error->content...
}
if($auth->captcha_url){
#display the image and get the answer from the user
#then try to login again
}
#everything is fine...
#give write access to the above user...
$base->auth($auth);
#now you can... (url are here for examples!)
#create a new entry with application/x-www-form-urlencoded content-type
my $ret = $base->post('http://gdata.youtube.com/feeds/api/users/default/playlists',$content);
#if it fails a first time, you will need to add captcha related parameters:
my $auth = new WebService::GData::ClientLogin(
email => '...',
password => '...',
captcha_token => '...',
captcha_answer => '...'
);
#youtube specific developer key
my $auth = new WebService::GData::ClientLogin(
email => '...',
password => '...',
key => '...',
);
DESCRIPTION
inherits from WebService::GData;
Google services supports different authorization systems allowing you to write data programmaticly. ClientLogin is one of such system.
This package tries to get an authorization key to the service specified by logging in with user account information: email and password.
If the loggin succeeds, the authorization key generated for you grants you access to write actions as long as you pass the key with each requests.
ClientLogin authorization key does expire but the expire time is set on a per service basis.
You should use this authorization system for installed applications.
Web application should use the OAuth (to be implemented) or AuthSub (will be deprecated and will not be implemented) authorization systems.
ClientLogin information can be found here:
http://code.google.com/intl/en/apis/accounts/docs/AuthForInstalledApps.html
CONSTRUCTOR
new
Takes an hash with the following parameters(parameters ended with * are optionals):
Specify the user email account.
password
Specifies the user password account.
service
Specify the service you want to loggin. youtube for youtube, cl for calendar,etc.
List available here:http://code.google.com/intl/en/apis/base/faq_gdata.html#clientlogin
Default to youtube.
source
Specify the name of your application in the following format "company_name-application_name-version_id".
Default to WebService::GData::ClientLogin-$VERSION but you should provide a real source to avoid getting blocked
because Google thought you are a bot...
type*
Specify the type of account: GOOGLE,HOSTED or HOSTED_OR_GOOGLE.
Default to HOSTED_OR_GOOGLE.
captcha_token*
Specify the captcha_token you received in response to a failure to log in.
captcha_answer*
Specify the answer of the user for the CAPTCHA.
Throws a WebService::GData::Error in case of failure.
GETTER METHODS
Returns the email address set to log in.
password
Returns the password set to log in.
source
Returns the source set to log in.
service
Returns the service set to log in.
type
Returns the account type set to log in.
captcha_token
Returns the captcha token sent back in case of failure with CaptchaRequired message.
captcha_url
Returns the captcha url sent back in case of failure with CaptchaRequired message. This url links to an image containing the challenge.
captcha_answer
Returns the captcha answer made by the user.
authorization_key
Returns the authorization key sent back in case of success.
key
Returns the developer key (youtube only).
HANDLING ERRORS/CAPTCHA
Google data APIs relies on querying remote urls on particular services.
All queries that fail will throw (die) a WebService::GData::Error object.
the CaptchaRequired does not throw an error.
Here is an example of how to implement the logic for a captcha in a web context.
(WARNING:shall not be used in a web context though but easy to grasp!)
Example:
use WebService::GData::ClientLogin;
my $auth;
eval {
$auth = new WebService::GData::ClientLogin(
email => '...',#from the user
password =>'...',#from the user
service =>'youtube',
source =>'MyCompany-MyApp-2'
);
};
if(my $error = $@) {
#something went wrong, display some info to the user
#$error->code,$error->content
}
#else it seems ok but...
#check to see if got back a captcha_url
if($auth->captcha_url){
#ok, so there was something wrong, we'll try again.
my $img = $auth->captcha_url;
my $key = $auth->captcha_token;
#here an html form as an example
#(WARNING:shall not be used in a web context but easy to grasp!)
print q[<form action="/cgi-bin/...mycaptcha.cgi" method="POST">];
print qq[<input type="hidden" value="$key" name="captcha_token"/>];
print qq[<input type="text" value="" name="email"/>];
print qq[<input type="text" value="" name="password"/>];
print qq[<img src="$img" />];
print qq[<input type="text" value="" name="captcha_answer"/>];
#submit button here
}
#once the form is submitted, in your mycaptcha.cgi program:
my $auth;
eval {
$auth = new WebService::GData::ClientLogin(
email => '...',#from the user
password =>'...',#from the user
service =>'youtube',
source =>'MyCompany-MyApp-2',
captcha_token => '...',#from the above form
captcha_answer => '...'#from the user
);
};
##error checking again...
CONFIGURATION AND ENVIRONMENT
none
DEPENDENCIES
INCOMPATIBILITIES
none
BUGS AND LIMITATIONS
If you do me the favor to _use_ this module and find a bug, please email me i will try to do my best to fix it (patches welcome)!
AUTHOR
shiriru <shiriru0111[arobas]hotmail.com>
LICENSE AND COPYRIGHT
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
11 POD Errors
The following errors were encountered while parsing the POD:
- Around line 212:
You can't have =items (as at line 216) unless the first thing after the =over is an =item
- Around line 268:
You forgot a '=back' before '=head2'
- Around line 274:
You forgot a '=back' before '=head2'
- Around line 280:
You forgot a '=back' before '=head2'
- Around line 286:
You forgot a '=back' before '=head2'
- Around line 292:
You forgot a '=back' before '=head2'
- Around line 298:
You forgot a '=back' before '=head2'
- Around line 305:
You forgot a '=back' before '=head2'
- Around line 311:
You forgot a '=back' before '=head2'
- Around line 317:
You forgot a '=back' before '=head2'
- Around line 325:
You forgot a '=back' before '=head1'