3
votes

I'm using the Google Calendar API to insert events in my customers Google Calendars. I want to insert events in the timezone of their calendar but currently I can only use one timezone via the Google Calendar API.

How can I get the timezone of a specific Google Calendar using the Google Calendar API?

By now I'm using the following code to add an event to a Google Calendar:

$eventName='You have ListingAppointments.com Appointment';
$Address='testing-456';
$Ausers='[email protected]';

if ($client->getAccessToken()) {
    $_SESSION['token'] = $client->getAccessToken();
    //print_r($events);
    $event = new Google_Event();
    $event->setSummary($eventName);
    $event->setLocation('testing234');

    $start = new Google_EventDateTime();
    $start->setDateTime('2013-07-19T10:25:00.000-07:00');
    //print_r($start);
    $event->setStart($start);

    $end = new Google_EventDateTime('2013-07-19T10:25:00.000-07:00');
    $end->setDateTime($end);
    //print_r($end);
    $event->setEnd($end);
    $attendee1 = new Google_EventAttendee();
    $attendee1->setEmail($Ausers);
    $attendees = array($attendee1);
    $event->attendees = $attendees;
    $createdEvent = $cal->events->insert('primary', $event);
    print_r($createdEvent);
}
1

1 Answers

4
votes

Give this code a try:-

$calendar = $cal->calendars->get('primary');
echo $calendar->getTimeZone();


line one gets you the primary calendar and line two gets you the timezone using getTimeZone() method.

or simply $cal->calendars->get('primary')->getTimezone();