通过Google Calendar API获取Google日历的时区

问题描述:

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='test48@gmail.com';

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);
}

我正在使用Google Calendar API在我的客户Google日历中插入活动。 我想在其日历的时区中插入活动,但目前我只能通过Google Calendar API使用一个时区。 p>

如何使用Google获取特定Google日历的时区 Calendar API? p>

现在我使用以下代码将事件添加到Google日历中: p>

  $ eventName =' 你有ListingAppointments.com Appointment'; 
 $ Address ='testing-456'; 
 $ Ausers ='test48@gmail.com'; 
 
if($ client-> getAccessToken()){
 $  _SESSION ['token'] = $ client-> getAccessToken(); 
 // print_r($ events); 
 $ event = new Google_Event(); 
 $ event-> setSummary($ eventName); \  n $ 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); 
} 
  code>  pre> 
  div>

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();