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
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
Related
I am sending email using Dancer2 via the Dancer2::Plugin::Email package. The main code that I have for this is:
sub sendEmail {
my ($params,$email_address,$template) = #_;
my $text = '';
my $tt = Template->new({
INCLUDE_PATH => config->{views},
INTERPOLATE => 1,
OUTPUT => \$text
}) || die "$Template::ERROR\n";
my $out = $tt->process($template,$params);
my $email = email {
from => XXXXX,
to => $email_address,
subject => XXXXX,
body => $text,
'Content-Type' => 'text/html'
};
}
where I have hidden a couple of the fields. I have gotten the following error:
Route exception: open body: Invalid argument at
/usr/local/share/perl/5.22.1/MIME/Entity.pm line 1878. in
/usr/local/share/perl/5.22.1/Dancer2/Core/App.pm l. 1454
It is not occurring all of the time and I haven't been able to find a consistent piece of code that always fails.
I have set the host parameter of the mail server that I am using in the configuration as explained here: https://metacpan.org/pod/Dancer2::Plugin::Email Simple tests show it works, but I get sporadic errors that I can't track down.
I'm trying to use Net::LDAPs with Net::LDAP::CONTROL::PAGED to return many records via a privlidged bind, but so far I have failed, miserably. I've used this Net::LDAPs extensively in the past, but I've never been able to find any documentation suggesting that it is compatible with Net::LDAP:Control::Paged. Everything I find is related to Net::LDAP.
The error message I get is: Undefined subroutine &main::process_entry called at /usr/local/share/perl/5.20.2/Net/LDAP/Search.pm line 55, line 755
Here is my code:
sub Ldap636{
my ($filter) = $_[0];
my $USERNAME = 'username';
my $PASSWORD = 'password';
my $LDAP_SERVER = 'directory.domain.edu';
my $LDAP_SSL_PORT = '636';
my $LDAP_BASE = 'ou=people,dc=domain,dc=edu';
my $userDN = "uid=$USERNAME,ou=identities,ou=special,dc=domain,dc=edu";
my $ldap = Net::LDAPS->new($LDAP_SERVER, port => $LDAP_SSL_PORT) or die "Could not create LDAP object because:\n$!";
my $ldapMsg = $ldap->bind($userDN, password => $PASSWORD);
die $ldapMsg->error if $ldapMsg->is_error;
my $page = Net::LDAP::Control::Paged->new( size => 100 );
#args = (base => "$LDAP_BASE",
callback => \&process_entry,
filter => $filter,
control => [ $page ],
);
my $cookie;
while (1) {
my $result = $ldap->search(#args);
"LDAP error: server says ",$result->error,"\n" if $result->code;
foreach my $entry ($result->entries ) {
my $cn = $entry->get_value('cn');
my $desc = $entry->get_value('description');
print "$cn - $desc\n";
}
# Get cookie from paged control
my($resp) = $result->control( LDAP_CONTROL_PAGED ) or last;
$cookie = $resp->cookie or last;
$page->cookie($cookie);
}
$ldap->unbind;
}
The error message I get is: Undefined subroutine &main::process_entry
called at /usr/local/share/perl/5.20.2/Net/LDAP/Search.pm line 55,
line 755
You have written process_entry as a callback but you didn't write that subroutine. That's why you are getting the above error.
I'm getting an error No form defined at cqSubmitter.pl at line 33 which is the second set_fields method. Other times I get an Error POSTing http://micron.com Internal Server Error at line 39 , which corresponds to the last click_button line.
I'm not really sure what's going on, and why it's saying no form defined? The first half of the code which includes the first click_button method works fine and saves the correct page, but when I try set_fields for the second time, it errors out.
Anyone familiar with the Mechanize package realize what's going on here?
use Data::Dumper;
use HTTP::Request::Common qw(GET);
use WWW::Mechanize;
#Prepopulated information
my $types_ = "";
my $dept_ = "";
my $group_ = "";
#Create new WWW::Mechanize object
my $mech = WWW::Mechanize->new( 'ssl_opts' => { 'verify_hostname' => 0 } );
my $url = "http://f2prbrequest";
#Fetch URL or Die Tryin'
$mech ->get($url);
$fname = "user";
$pswd = "password";
#Login to ClearQuest form using credentials
$mech->set_fields(
USER => $fname
,PASSWORD => $pswd
);
$mech->click_button(
name => 'Submit'
);
#Set fields and actually fill out ClearQuest Form
$mech->set_fields(
types => $types_
,dept => $dept_
,group => $group_
);
$mech->click_button(
name => 'submit1'
);
$mech->save_content("clearQuestFilled.html");
We have private MediaWiki installation inside our company. Based on daily builds on our source code, we update the wiki with Perforce labels so that people can use the build that is labeled for streamlined process. We tried to automate this using Perl scripts on a Windows server using MediaWiki::Bot and MediaWiki::API.
use MediaWiki::Bot;
use MediaWiki::API;
my $mw = MediaWiki::API->new();
$mw->{config}->{api_url} = 'http://somewiki/w/index.php/title#feature_List';
# log in to the wiki
$mw->login({
lgname => 'username',
lgpassword => 'password'
|| die $mw->{error}->{code} . ': ' . $mw->{error}->{details};
# get a list of articles in category
my $articles = $mw->list({
action => 'query',
list => 'categorymembers',
cmtitle => 'Category:Perl',
cmlimit => 'max'
}) || die $mw->{error}->{code} . ': ' . $mw->{error}->{details};
# and print the article titles
foreach (#{$articles}) {
print "$_->{title}\n";
}
Output:
2: Failed to decode JSON returned by http://vaporwiki/w/index.php/Executor#Execu
tor_Feature_List
Decoding Error:
malformed JSON string, neither array, object, number, string or atom, at charact
er offset 0 (before "<!DOCTYPE html PUBLI...") at C:/Perl/lib/MediaWiki/API.pm l
ine 398
Returned Data: <whole page data>
The API URL is wrong. Try http://vaporwiki/w/api.php.
I'm trying to use Net::Google::Spreadsheets to manipulate a Google Docs spreadsheet (side note: you may have seen my previous question where I was trying to work from the inside of Google Docs, now I'm trying a different angle)
I'm trying an example pretty much straight out of the perldoc:
#!/usr/bin/perl
use strict;
use warnings;
use Net::Google::Spreadsheets;
my $service = Net::Google::Spreadsheets->new(
username => 'my.email#gmail.com',
password => 'mypassword'
);
my #spreadsheets = $service->spreadsheets();
# find a spreadsheet by key
my $spreadsheet = $service->spreadsheet(
{
title => 'Perl Test' # This is a spreadsheet I manually created already
}
);
# find a worksheet by title
my $worksheet = $spreadsheet->worksheet(
{
title => 'Sheet1'
}
);
my $cell = $worksheet->cell({col => 1, row => 1});
# update input value of a cell
$cell->input_value('new value');
When I run my code, I get this error:
request for 'https://spreadsheets.google.com/feeds/worksheets/tNdoUPkz7MhRAtVoBaaZVHQ/private/full?title=Sheet1' failed:
500 Internal Server Error
Internal Error
at /usr/local/share/perl/5.10.1/Net/Google/DataAPI/Role/Service.pm line 96
Net::Google::DataAPI::Role::Service::request('Net::Google::Spreadsheets=HASH(0x167ce60)', 'HASH(0x1c63ba8)') called at /usr/local/share/perl/5.10.1/Net/Google/DataAPI/Role/Service.pm line 158
Net::Google::DataAPI::Role::Service::get_feed('Net::Google::Spreadsheets=HASH(0x167ce60)', 'https://spreadsheets.google.com/feeds/worksheets/tNdoUPkz7MhR...', 'HASH(0x1a38d58)') called at /usr/local/share/perl/5.10.1/Net/Google/DataAPI.pm line 106
Net::Google::Spreadsheets::Spreadsheet::worksheets('Net::Google::Spreadsheets::Spreadsheet=HASH(0x1a36460)', 'HASH(0x1a38d58)') called at /usr/local/share/perl/5.10.1/Net/Google/DataAPI.pm line 119
Net::Google::Spreadsheets::Spreadsheet::worksheet('Net::Google::Spreadsheets::Spreadsheet=HASH(0x1a36460)', 'HASH(0x1a38d58)') called at spreadsheet_test.pl line 22
And then if I try to open up the Perl Test spreadsheet from within Google Docs, Google itself gives me the equivalent of a 500 error.
So what am I doing wrong?