I had problems with this for a long time and was finally able to
figure it out by skimming a lot of other posts...maybe having this
code all in one place will help others too!

The basic method is this:
- Authenticate and get a valid Zend_Http_Client object
- Use the client object to get a Zend_Gdata_Calendar object
- Call getCalendarListFeed to get a list of calendars
- Retrieve the user id of the calendar you wish to query (The user id
is a part of the calendar's "id" field in the list feed...it's the
part at the end, after "http://www.google.com/calendar/feeds/
default/". For your default calendar, it is your email address. Other
calendars have randomly generated user id's)
- Use the functions setUser (with the user id of the desired
calendar), setVisibility, setProjection, setOrderBy, and possibly
setStartMin and setStartMax, to prepare the calendar object
- Call getCalendarFeed() to get a feed from the calendar you
specified!

<code>
        /**
        * Get a list of user's calendars
        *
        * @author Andrew Richardson (http://pc.byethost10.com)
        * @param Zend_Http_Client $client
        * @return array associative array of calendars (title => user_id)
        */
        function gcal_EnumCalendars($client) {
                $cal = new Zend_Gdata_Calendar($client);
                $calFeed = $cal->getCalendarListFeed();

                $calendars = array();
                foreach ($calFeed as $calendar) {
                        # Get the calendar's actual name
                        $title = $calendar->title();

                        # Look for an override name (if user has renamed a 
calendar that
was shared with them)
                        $override = $calendar->getDOM()-
>getElementsByTagName('overridename');
                        foreach($override as $o) {
                                $title = $o->getAttribute('value');
                        }

                        # Add this calendar to the array
                        $feed = explode('/', $calendar->id());
                        $calendars[$title] = urldecode($feed[6]);
                }
                return $calendars;
        }

        /**
        * Get events from a calendar
        *
        * @author Andrew Richardson (http://pc.byethost10.com)
        * @param Zend_Http_Client $client
        * @param string $id user_id of calendar to use (defaults to
'default')
        * @param integer $first in epoch seconds, the minimum date to list
(defaults to today)
        * @param integer $last in epoch seconds, the maximum date to list
(defaults to infinity)
        * @return array associative array of events (title => ('start' =>
start, 'end' => end))
        */
        function gcal_GetEvents($client, $id, $first, $last) {
                $cal = new Zend_Gdata_Calendar($client);
                if(isset($id)) $cal->setUser($id);
                else $cal->setUser('default');
                $cal->setVisibility('private');
                $cal->setProjection('full');
                $cal->setOrderby('starttime');

                # Default range is from today until the end of time
                if(!isset($first)) $first = time();
                $firstdate = getdate($first);
                $cal->setStartMin($firstdate['year'] . '-' . $firstdate['mon'] .
'-1');

                if(isset($last)) {
                        $lastdate = getdate($last);
                        $cal->setStartMax($lastdate['year'] . '-' . 
$lastdate['mon'] .
'-1');
                }

                # Parse the date of each event
                $eventFeed = $cal->getCalendarFeed();
                $events = array();
                foreach ($eventFeed as $eventFeed) {
                        $start = strtotime( 
$eventFeed->{'gd:when'}['startTime'] );
                        $end   = strtotime( $eventFeed->{'gd:when'}['endTime']  
 );

                        $event = array("start" => $start, "end" => $end);
                        $events[ $eventFeed->title() ] = $event;
                }

                return $events;
        }
</code>

An example use of the code, assuming I have a valid client object
already, and assuming my Google Calendar account includes a non-
default calendar entitled "Work Schedule":
<code>
$calendars = gcal_EnumCalendars($client);
$events = gcal_GetEvents( $client, $calendars['Work Schedule'] );
foreach($events as $title => $event) {
        print $title;
        print_r( $event );
}
</code>

On Apr 24, 8:12 pm, Paul <[EMAIL PROTECTED]> wrote:
> I posted this tohttp://www.nabble.com/Zend-gdata-f16698.htmlbut
> didn't get a response.  I searched the net and this group's archives
> but met a similarly unproductive fate.
>
> I've managed to write a command-line PHP  program that uses
> ClientLogin to access my users'sdefaultcalendar("A").  When I do a
> $eventFeed = $gdataCal->getCalendarFeed(), I get back a feed
> ($eventFeed) happily listing all of the events in mydefaultcalendar
> ("A").  When I $myCalendarList = $gdataCal->getCalendarListFeed(), I
> get back a feed listing all of 5 of calendars ("A", "B", "C", "D" and
> "E")... but there are no events in the $myCalendarList object, as you
> might (correctly) infer from the name of the getCalendarListFeed
> function.
>
> How do I combine these two ideas (1-getting acalendar'sevents and 2-
> getting a listing of my calendars) to access the events in my 
> non-defaultcalendar?
>
> Thanks for any assistance,
>
> --Paul


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Calendar Data API" group.
To post to this group, send email to 
google-calendar-help-dataapi@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-calendar-help-dataapi?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to