получение контактов из Net::OAuth::Simple make_restricted_request

Я могу получить авторизованные токены и даже получить результаты от make_restricted_request, но я не могу интерпретировать результаты. Все они такие- 13T01:26:56.834Zhttp://www.google.com/m8/feeds/contacts/userEMAIL/base/12010-01-

Однако кажется, что это фактические результаты, их ровно столько, сколько указано в значении «max-results» в запросе ниже.


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;

Вывод (100 строк), например:

$VAR1 = благословить( { '_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- ...


person user2040657    schedule 27.02.2014    source источник


Ответы (1)


$response, возвращенный из make_restricted_request, представляет собой объект HTTP::Response. Net::OAuth::Simple уже проверяет успешность запроса, поэтому вы можете получить доступ к содержимому ответа, используя $response->content или $response->decoded_content.

person nwellnhof    schedule 27.02.2014