Reputation: 165
I am trying to use Perl google spreadsheet API and i am getting stuck in this error. I did exactly as per the doc at http://search.cpan.org/~danjou/Net-Google-Spreadsheets-0.1501/lib/Net/Google/Spreadsheets.pm
Here is the code
use Net::Google::Spreadsheets;
use Net::Google::DataAPI::Auth::OAuth2;
use Net::OAuth2::AccessToken;
my $oauth2;
my $service;
$oauth2 = Net::Google::DataAPI::Auth::OAuth2->new(
client_id => '<clientid>',
client_secret => '<client secret>',
scope => ['http://spreadsheets.google.com/feeds/'],
);
my $url = $oauth2->authorize_url(
access_type => 'offline',
approval_prompt => 'force',
);
print "$url\nEnter the code: ";
my $code = <STDIN>;
my $access_token = $oauth2->get_access_token($code) or die;
$service = Net::Google::Spreadsheets->new(auth => $oauth2);
print "Testing Spreadsheet";
# find a spreadsheet by key
my $spreadsheet = $service->spreadsheet( { key => '<spread sheet key>' }) or die $!;
It does not throw error during Oauth but when I try to access the spreadsheet API it gives me the following error.
Use of uninitialized value $nsURI in string eq at /usr/local/lib/perl5/site_perl/5.14.2/mach/XML/LibXML.pm line 1705. at /usr/local/lib/perl5/site_perl/5.14.2/mach/XML/LibXML.pm line 1699. XML::LibXML::Element::getElementsByTagNameNS(XML::LibXML::Element=SCALAR(0x80416ed20), undef, "entry") called at /usr/local/lib/perl5/site_perl/5.14.2/XML/Atom/Feed.pm line 84 XML::Atom::Feed::entries_libxml(XML::Atom::Feed=HASH(0x8041938e8)) called at /usr/local/lib/perl5/site_perl/5.14.2/Net/Google/DataAPI.pm line 113 Net::Google::Spreadsheets::spreadsheets(Net::Google::Spreadsheets=HASH(0x803045600), HASH(0x802a5cb70)) called at /usr/local/lib/perl5/site_perl/5.14.2/Net/Google/Spreadsheets.pm line 57 Net::Google::Spreadsheets::ANON(CODE(0x803020438), Net::Google::Spreadsheets=HASH(0x803045600), HASH(0x802a5cb70)) called at /usr/local/lib/perl5/site_perl/5.14.2/mach/Mouse/Meta/Class.pm line 381 Mouse::Meta::Class::ANON(Net::Google::Spreadsheets=HASH(0x803045600), HASH(0x802a5cb70)) called at /usr/local/lib/perl5/site_perl/5.14.2/mach/Mouse/Meta/Class.pm line 334 Net::Google::Spreadsheets::spreadsheets(Net::Google::Spreadsheets=HASH(0x803045600), HASH(0x802a5cb70)) called at /usr/local/lib/perl5/site_perl/5.14.2/Net/Google/DataAPI.pm line 132 Net::Google::Spreadsheets::spreadsheet(Net::Google::Spreadsheets=HASH(0x803045600), HASH(0x802a5cb70)) called at try.pl line 62
Upvotes: 0
Views: 232
Reputation: 165
For anyone having the same problem here is the solution.
Looks like between the time when this module was written and today google has changed their API so the documentation of the module needs to be modified.
By changing the key => 'the key' to id => 'the key' solved the problem.
So the correct way to get the spreadsheet would be
my $spreadsheet = $service->spreadsheet( { id => '<spread sheet key>' }) or die
$!;
The key is part of the url https://docs.google.com/spreadsheets/d/[spreadsheetkey]/edit
Upvotes: 0