Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Anyone know how to use the Net::Google::Calendar API?

by leocharre (Priest)
on Dec 07, 2009 at 19:40 UTC ( [id://811611]=perlquestion: print w/replies, xml ) Need Help??

leocharre has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to access google calendars via the command line. I just want a list of events spat out.

I'm trying out Net::Google::Calendar with not much success. The documentation is creepy- the module has good reviews and it seems a lot of work was put into it.

use Net::Google::Calendar; use Smart::Comments '###'; my $c = Net::Google::Calendar->new; $c->login( $username, $password ); my @calendars = $c->get_calendars; # great, this works- it returns a 5 element list # this next line however.. my @e = $c->get_events; warn "ecount ".@e; ### @e for my $cal (@calendars){ printf "title %s, id %s\n", $cal->title, $cal->id; my @e = $cal->get_events; for (@e){ printf "event %s %s\n", $_->title, $_->content->body; } }

Im trying to get a list of events..

If I don't try to get_events() from the main calendar object created, it goes on fine to list title and id (private url) of each calendar.

As it is.. I get an error when I call get_events() 400 Bad Request at /usr/lib/perl5/site_perl/5.8.8/Net/Google/Calendar.pm line 577.

and then..

Argh.. anyhow.. I figure I must be using the interface wrong- Anyone know how to use the Net::Google::Calendar API?

Replies are listed 'Best First'.
Re: Anyone know how to use the Net::Google::Calendar API?
by desemondo (Hermit) on Dec 08, 2009 at 02:48 UTC
    the docos are rather vague aren't they...

    I had a look through the test suite and the example file google-calendar, and noticed that set_calendar($c) seems to be used prior to calling get_events()... Its entirely possible that this example file is very old and that requirement is now obselete. But FWIW, that was the only difference that jumped out at me while comparing your code with the example...

    I haven't got the module installed so can't test it - but hopefully its a step in the right direction...
    good hunting...

    Update: Added in snippet to which i was referring to...
    my @calendars = $cal->get_calendars; my ($c) = grep { $_->title =~ m!default!i } $cal->get_calendars; #die "Couldn't get cal\n" unless defined $c; $c = $calendars[0]; $cal->set_calendar($c); if (!@ARGV) { print "Getting events\n"; for ($cal->get_events()) { #print Dumper $_->as_xml; #next; print $_->title."\n"; print $_->id."\n"; my ($start, $finish) = $_->when(); print "${start}-${finish}\n"; #print $_->content->body; print "\n*****\n\n"; } exit; }
    Update2: Just noticed that Simon Wistow still considers this module to be Alpha... could well be that get_events simply doesn't work properly yet...
      Aha! Guess what! That was it... Have to call set_calendar()..
      # pseudocode: my $parent = Net::Google::Calendar->new; $parent->login( $uname, $upass); my @cals = $parent->get_calendars; for my $cal_selected (@cals) { printf "CALENDAR: %s\n", $cal_selected->title; $parent->set_calendar( $cal ); my @e = $parent->get_events; for (@e){ printf "event title: %s, content: %s\n", $_->title, $_->content->body; } }

      Yes Wistow notes 'Alpha'- that said, some reviewees state the thing 'does what they need' - so- missing this functinality- it seems odd it would be of use at all- that's why I thought maybe I was off..

      I'm kinda torn about using oo this way, it's really weird.. it seems we should instance a calendar object, and *it* should have a get_events() method, no?

      This other way is kind of interesting too.. passing around objects like little toys..

      Thank you!!!!!!

        Hi

        Does anyone know how to create and save a new Calendar using this module? I know it's doable
        http://code.google.com/apis/calendar/data/2.0/developers_guide_protocol.html#CreatingCalendars
        I have no clue how to achieve it with the API :(.

        thanks for any suggestions

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://811611]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-03-29 13:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found