Question

I am able to get authorized tokens and even get results from make_restricted_request but I cannot interpret the results. They are all like- 13T01:26:56.834Zhttp://www.google.com/m8/feeds/contacts/userEMAIL/base/12010-01-

However it seems they are actual results there are exactly as many results as the 'max-results' value I provide in the request below.


package Net::AppThatUsesOAuth;

use strict;
use base qw(Net::OAuth::Simple);

sub new {
    my $class  = shift;
    my %tokens = @_;

    return $class->SUPER::new( tokens => \%tokens,
                               protocol_version => '1.0a',
                               urls   => {
                                    request_token_url => "https://www.google.com/accounts/OAuthGetRequestToken?scope=https://www.google.com/m8/feeds/",
                                    authorization_url => "https://www.google.com/accounts/OAuthAuthorizeToken",
                                    access_token_url  => "https://www.google.com/accounts/OAuthGetAccessToken",
                               });
}


sub view_restricted_resource {
    my $self = shift;
    my $url= 'https://www.google.com/m8/feeds/contacts/default/full' ;
    return $self->make_restricted_request($url, 'GET', 'max-results' => 100 );
}

package main;
use CGI;
use Data::Dumper;

my $cgi = new CGI;
print $cgi->header(-charset => 'utf-8');

my $app     = Net::AppThatUsesOAuth->new(%tokens);
if ($app->authorized) {
   my $response = $app->view_restricted_resource;
   print "Restricted resource = ".(Dumper $response)."\n";
}
exit;

Output is (100 rows) like :

$VAR1 = bless( { '_protocol' => 'HTTP/1.1', '_content' => 'userEMAIL2014-02-27T02:15:52.254ZuserNAMEuserEMAILContacts10361100http://www.google.com/m8/feeds/contacts/userEMAIL/base/02012-04-13T01:26:56.834Zhttp://www.google.com/m8/feeds/contacts/userEMAIL/base/12010-01-21T19:32:41.739Zhttp://www.google.com/m8/feeds/contacts/userEMAIL/base/22008-04-09T08:47:53.076Zhttp://www.google.com/m8/feeds/contacts/userEMAIL/base/32010-01-21T19:32:41.739Zhttp://www.google.com/m8/feeds/contacts/userEMAIL/base/42008-04- ...

Was it helpful?

Solution

The $response returned from make_restricted_request is a HTTP::Response object. Net::OAuth::Simple already checks whether the request is successful, so you can access the content of the response using $response->content or $response->decoded_content.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top