Skip to content

Instantly share code, notes, and snippets.

@typester
Created July 26, 2010 05:03
Show Gist options
  • Save typester/490201 to your computer and use it in GitHub Desktop.
Save typester/490201 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use Config::Pit;
use LWP::UserAgent;
use Net::Google::AuthSub;
my $file = $ARGV[0] or die 'require filename';
open my $fh, '<', $file or die $!;
my $data = do { local $/; <$fh> };
close $fh;
my $conf = pit_get('google.com', require => {
username => 'your google username',
password => 'your google password',
});
# login
my %auth_params = do {
my $auth = Net::Google::AuthSub->new( service => 'writely' );
my $res = $auth->login(@{$conf}{qw/username password/});
die 'Login failed: ' . $res->error
unless $res->is_success;
$auth->auth_params;
};
my $req =
HTTP::Request->new( POST => 'https://docs.google.com/feeds/default/private/full?ocr=true' );
$req->header( 'GData-Version' => '3.0' );
$req->header( 'Slug' => 'OCRd Doc' );
while (my ($k, $v) = each %auth_params) {
$req->header($k, $v);
}
$req->header( 'Content-Length' => length $data );
$req->header( 'Content-Type' => 'image/png' );
$req->content($data);
my $ua = LWP::UserAgent->new;
my $res = $ua->request($req);
warn $res->as_string;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment