creating google calendar event

前端 未结 2 1481
终归单人心
终归单人心 2021-01-03 15:49

am trying to create google calendar event using the following code given below, but am getting class Event not found . How to create a new event. please help



        
相关标签:
2条回答
  • 2021-01-03 16:29

    I had the exact same problem. Their documentation very incomplete. The class names are wrong in their example. Here is the code I got to work:

    $event = new Google_Event();
    $event->setSummary('Halloween');
    $event->setLocation('The Neighbourhood');
    $start = new Google_EventDateTime();
    $start->setDateTime('2012-10-31T10:00:00.000-05:00');
    $event->setStart($start);
    $end = new Google_EventDateTime();
    $end->setDateTime('2012-10-31T10:25:00.000-05:00');
    $event->setEnd($end);
    $createdEvent = $cal->events->insert('[calendar id]', $event); //Returns array not an object
    
    echo $createdEvent->id;
    

    $cal->events->insert returns an array, not an object like in their example code. If you want it to return an object you need to define it in your Google_Client call, like so:

    $client = new Google_Client(array('use_objects' => true));
    
    0 讨论(0)
  • 2021-01-03 16:46

    I had this problem too, and it seems things have changed with Google's API again.

    Using the code example in the docs I was trying do

    $calendar = new Calendar();
    

    This threw an error for class Calendar not found. Turns out everything was renamed and I had to do the following:

    $calendar = new Google_Service_Calendar_Calendar();
    

    Seems like an ok naming convention to avoid conflicts, but it would have been nice to update the docs. So to solve OP's problem today he would now solve his issue using:

    $event = new Google_Service_Calendar_Event();
    

    You can look through the file Google/Service/Calendar.php and you should see all the relevant classes named with this naming convention.

    0 讨论(0)
提交回复
热议问题