No problem.

Because I'm feeling nice, I'll add some more :)

Heres a POST call - slightly different - make a document in google
docs:

#!/usr/bin/perl -w

use Net::OAuth;
use LWP::UserAgent;
use Data::Dumper;
use HTTP::Request qw(:strict);

my $key         = 'replace with oauth consumer key';
my $secret      = 'replace with oauth consumer secret';
my $username    = 'replace with valid username on hosted domain';

my $req_url     = 'http://docs.google.com/feeds/documents/private/
full';
my $email       = $username.'@'.$key;
my $xoauth      = 'xoauth_requestor_id';
my $extra_arg   = 'max-results';
my $extra_val   = '50';
my $req_method  = 'POST';
my $sig_method  = 'HMAC-SHA1';
my $timestamp   = time;
my $nonce       = int(rand(99999999));

my $geturl    = $req_url.'?'.$xoauth.'='.$email;
my $request = Net::OAuth->request('consumer')->new(
        consumer_key => $key,
        consumer_secret => $secret,
        request_url =>  $req_url,
        request_method => $req_method,
        signature_method => $sig_method,
        timestamp => $timestamp,
        nonce => $nonce,
        extra_params => {
           $xoauth => $email,
        }
);

 my $content = '<atom:entry xmlns:atom="http://www.w3.org/2005/Atom";>
   <atom:category scheme="http://schemas.google.com/g/2005#kind";
                 term="http://schemas.google.com/docs/2007#document"; /
>
  <atom:title>Company Perks</atom:title>
 </atom:entry>';

$request->sign;

my $lwp_object = LWP::UserAgent->new;
my $req = HTTP::Request->new(POST => $geturl);
$req->header('Content-Type' => 'application/atom+xml');
$req->header('Authorization' => $request->to_authorization_header);
$req->header('Accept-Encoding' => 'identity');
$req->content($content);

my $response = $lwp_object->request($req);
print Dumper($response);



Something else I've figured out (this may be terribly obvious, but
again, I hope it helps someone) - following a redirect when
interacting with something like, say 
http://www.google.com/calendar/feeds/default/allcalendars/full
isn't as simple as directly resubmitting the request at the new url.

Resubmitting the existing signed authorization header to the new url
doesn't work because the new url has a gsessionid value appended to
it, and a different base url value, meaning that the signature won't
match what the server is expecting on its side.

Update the request_url in the hash with its new value, and add the
gsessionid and its value to the extra_params hash.

Heres an ugly snippet that does this: (Yes, I'm aware that one can do
the split and foreach bit with a library, but obvious is good, right..
right? :) )

my $redirect =  $response->header('location');
my ($dom,$query_string) = split (/\?/,$redirect);

foreach my $pair (split(/&/, $query_string)) {
    my ($_n, $_v) = split(/=/, $pair);
    $qs{$_n} = $_v;
}

$request->{extra_params}->{gsessionid} = $qs{'gsessionid'};
$request->{request_url} = $dom;
$request->sign;

$req_url = $dom;
$geturl = $req_url.'?'.$xoauth.'='.$email.'&.'gsessionid'.'='.$qs
{'gsessionid'};

Resubmit that, and it should auth with the calendaring service
properly, and any others that have redirects in them. I do remember
reading somewhere that redirects are part of the OAuth spec (might
have been the actual spec...), so one probably should be defensively
coding against them, rather than on a case by case basis.

Cheers,
David
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Apps APIs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-apps-apis?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to