Created
July 26, 2010 05:03
-
-
Save typester/490201 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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