Updating Google Calendar event

耗尽温柔 提交于 2020-01-17 05:32:29

问题


I have been reading over the internet, but none of the codes work, to update an event. The event ID is sent from an other page. And this works.

$eventId= $_GET['id'];
$event = new Google_Event($service->events->get($calendarId, $eventId));
$event->setLocation('Home');
$event->setSummary('Summary');
    //$start = new Google_EventDateTime();
    //$start->setDateTime($fstart);
    //$event->setStart($start);
    //$end = new Google_EventDateTime();
    //$end->setDateTime($ssend);
    //$event->setEnd($fEnd);
    $updated = new Google_Event($service->events->update($calendarId, $event->getId(), $event));

When doing this I get an error:

(get) missing required param: 'eventId'

I have done at first

echo 'Event ID:' .$eventId;

And this gave me the right eventid.

I'm already 3 weeks on this peace of code that doesn't work.

This is the complete page without form:

<?php
error_reporting(E_ALL);

//Required Files
include ($_SERVER['DOCUMENT_ROOT']."/style/style.php");
require_once($_SERVER['DOCUMENT_ROOT']."/google/src/autoload.php");
require_once($_SERVER ['DOCUMENT_ROOT']."/google/src/Google_Client.php");
require_once($_SERVER['DOCUMENT_ROOT']."/google/src/contrib/Google_CalendarService.php"); 
//Developpers Account details
$client_id = 'xxx.apps.googleusercontent.com';
$Email_address = 'xxx@developer.gserviceaccount.com';    
$key_file_location = ($_SERVER  ['DOCUMENT_ROOT']."/key/xxx.p12");
$scopes ="https://www.googleapis.com/auth/calendar";
$calid = "xxx@gmail.com";
//Set new Client
$client = new Google_Client();
$client->setUseObjects(true);       
$client->setApplicationName("Update");
$client->setClientId($client_id);    
$client->setAssertionCredentials(
        new Google_AssertionCredentials
        (
            $Email_address,
            array(
                    $scopes
                 ),
                    file_get_contents($key_file_location)
                 )
        );  
$service = new Google_CalendarService($client);

//Retreive Event
$eventId= $_GET['id'];//sended thru POST by url


// First retrieve the event from the API.
$event = $service->events->get($calid,$eventId);
$event->setSummary('Hello there');
$event->setLocation('Somewhere');
$updatedEvent = $service->events->update($calid, $event->getId(),$event);

// Print the updated date.
echo $updatedEvent->getUpdated();

?>

来源:https://stackoverflow.com/questions/32172220/updating-google-calendar-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!