I've been thinking about redoing my news reader plugin for Movable Type based around Google Reader. In order to do that, I had to find out some things about the Google Reader API, at least as far as is publicly known about its API (if you can call it that). This blog post proved to be invaluable in getting this working sample (and understanding) up and running. It's ugly as hell, and I know there is a CPAN module for GoogleReader (that may or may not still be working), but I figured I'd learn how it works through trial and error in order to better understand it.
use strict;
use LWP;
use HTTP::Cookies;
use HTTP::Request;
use HTTP::Response;
use HTTP::Request::Common qw( GET POST );
use URI;
use URI::Escape;
use URI::QueryParam;
my $login = 'me@gmail.com';
my $password = '*******';
my $source = 'CMR';
my $google_url = 'http://www.google.com';
my $reader_url = $google_url . '/reader';
my $login_url = 'https://www.google.com/accounts/ClientLogin';
my $token_url = $reader_url . '/api/0/token';
my $subscription_list_url = $reader_url . '/api/0/subscription/list';
my $reading_url = $reader_url . '/atom/user/-/state/com.google/reading-list';
my $read_items_url = $reader_url . '/atom/user/-/state/com.google/read';
my $reading_tag_url = $reader_url . '/atom/user/-/label/%s';
my $starred_url = $reader_url . '/atom/user/-/state/com.google/starred';
my $subscription_url = $reader_url . '/api/0/subscription/edit';
my $get_feed_url = $reader_url . '/atom/feed/';
my $browser = LWP::UserAgent->new(agent => $source);
my $response = $browser->post($login_url, [
'Email' => $login,
'Passwd' => $password,
'service' => 'reader',
'continue' => $google_url,
'source' => $source
]);
my $sidline = $response->{_content};
my $sid = substr($sidline, length("SID="), length($sidline));
my @parts = split(/\n/, $sidline);
$sid = substr($parts[0], length("SID="), length($parts[0]));
print "$sid\n";
unless ( $browser->cookie_jar ) {
$browser->cookie_jar( HTTP::Cookies->new( hide_cookie2 => 1 ) );
}
$browser->cookie_jar->set_cookie(0, SID=>$sid, '/', '.google.com', undef, 1, 0, 160000000000);
my $uri = URI->new($subscription_list_url);
my $req = GET($uri);
$req->uri->query_param( ck => time * 1000);
$req->uri->query_param( client => $browser->agent);
$req->uri->query_form( { $uri->query_form, output => 'xml'} );
my $res = $browser->request($req);
if ($res->is_error()) { print "ERROR!!!!\n"; }
print $req->as_string() . "\n";
print $res->decoded_content() . "\n";
use strict;
use LWP;
use HTTP::Cookies;
use HTTP::Request;
use HTTP::Response;
use HTTP::Request::Common qw( GET POST );
use URI;
use URI::Escape;
use URI::QueryParam;
my $login = 'me@gmail.com';
my $password = '*******';
my $source = 'CMR';
my $google_url = 'http://www.google.com';
my $reader_url = $google_url . '/reader';
my $login_url = 'https://www.google.com/accounts/ClientLogin';
my $token_url = $reader_url . '/api/0/token';
my $subscription_list_url = $reader_url . '/api/0/subscription/list';
my $reading_url = $reader_url . '/atom/user/-/state/com.google/reading-list';
my $read_items_url = $reader_url . '/atom/user/-/state/com.google/read';
my $reading_tag_url = $reader_url . '/atom/user/-/label/%s';
my $starred_url = $reader_url . '/atom/user/-/state/com.google/starred';
my $subscription_url = $reader_url . '/api/0/subscription/edit';
my $get_feed_url = $reader_url . '/atom/feed/';
my $browser = LWP::UserAgent->new(agent => $source);
my $response = $browser->post($login_url, [
'Email' => $login,
'Passwd' => $password,
'service' => 'reader',
'continue' => $google_url,
'source' => $source
]);
my $sidline = $response->{_content};
my $sid = substr($sidline, length("SID="), length($sidline));
my @parts = split(/\n/, $sidline);
$sid = substr($parts[0], length("SID="), length($parts[0]));
print "$sid\n";
unless ( $browser->cookie_jar ) {
$browser->cookie_jar( HTTP::Cookies->new( hide_cookie2 => 1 ) );
}
$browser->cookie_jar->set_cookie(0, SID=>$sid, '/', '.google.com', undef, 1, 0, 160000000000);
my $uri = URI->new($subscription_list_url);
my $req = GET($uri);
$req->uri->query_param( ck => time * 1000);
$req->uri->query_param( client => $browser->agent);
$req->uri->query_form( { $uri->query_form, output => 'xml'} );
my $res = $browser->request($req);
if ($res->is_error()) { print "ERROR!!!!\n"; }
print $req->as_string() . "\n";
print $res->decoded_content() . "\n";
Hi Mike,
Thanks for the posting, got me through a couple of issues!
Regards,
Gareth