Thanks a lot David. This is wonderful and much appreciated! -Anirudh
On Jan 30, 6:42 am, DavidMurrell <[email protected]> wrote: > After much gnashing of teeth, I've got some simple OAuth code working. > Since > I couldn't find any 2 legged example code that particularly pertained > to > doing OAuth for Google Apps, I figure I'll post mine in the hope that > it > might help someone else. > > I've added an example into the extra_params section to make things a > bit > clearer about where url arguments go (in this case max-results=50). > > This is written for clarity, not because its particularly elegant... > > Cheers, > David Murrell > > #!/usr/bin/perl -w > > use Net::OAuth; > use HTTP::Request::Common; > use LWP::UserAgent; > use Data::Dumper; > > 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://www.google.com/m8/feeds/contacts/default/ > full'; > my $email = $username.'@'.$key; > my $xoauth = 'xoauth_requestor_id'; > my $extra_arg = 'max-results'; > my $extra_val = '50'; > my $req_method = 'GET'; > my $sig_method = 'HMAC-SHA1'; > my $timestamp = time; > my $nonce = int(rand(99999999)); > > my $geturl = $req_url.'?'.$xoauth.'='.$email.'&'.$extra_arg.'='. > $extra_val; > > 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 => { > $extra_arg => $extra_val, > $xoauth => $email, > } > ); > > $request->sign; > > my $lwp_object = LWP::UserAgent->new; > $lwp_object->default_header('Content-type' => 'application/atom+xml'); > $lwp_object->default_header('Authorization' => > $request->to_authorization_header); > $lwp_object->default_header('Accept-Encoding' => 'identity'); > > my $response = $lwp_object->get( $geturl ); > > print Dumper($response); --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
