Reputation: 2775
It's a newbie question, I'm not used to the Google API yet
Hi,
I'm using the code provided by Google ( https://developers.google.com/google-apps/calendar/downloads ) that are coming with some examples (originally because it seemed more up-to-date).
I am successfully retrieving the calendars as the example "calendar/simple.php" shows (OAuth2 setup is correct).
After that, I'm doing this and it works (it's a non necessary code, just for checking if the event can be retrieved properly without any error):
$test = $cal->events->get("[email protected]","longeventcodegivenbygoogle");
Now, I want to be able to set some values of a specific event.
$event = new Event();
$event->setLocation('Somewhere');
$test = $cal->events->update("[email protected]","longeventcodegivenbygoogle",$event);
But it's giving me:
( ! ) Fatal error: Uncaught exception 'apiServiceException' with message 'Error calling PUT https://www.googleapis.com/calendar/v3/calendars/[email protected]/events/longeventcodegivenbygoogle?key=myapikey: (400) Required' in C:\wamp\www\test\Gapi3\src\io\apiREST.php on line 86
( ! ) apiServiceException: Error calling PUT https://www.googleapis.com/calendar/v3/calendars/[email protected]/events/longeventcodegivenbygoogle?key=myapikey: (400) Required in C:\wamp\www\test\Gapi3\src\io\apiREST.php on line 86
What do I do wrong?
Thanks for your help.
Upvotes: 2
Views: 8265
Reputation: 2775
The real solution is given by Claudio Cherubino with a call of the event Class to create the event object.
By default, it seems that the get() does not return an event object but an array.
$event = new Event($cal->events->get("[email protected]","longeventcodegivenbygoogle"));
$event->setLocation('Somewhere');
$updated = new Event($cal->events->update("[email protected]", $event->getId(), $event));
If you do not create the event with the array supplied by update() or get() it will not work since it's a simple array that is being returned by these calls.
Upvotes: 4
Reputation: 15004
In order to update an event, you retrieve it first and then change the values of its properties instead of instantiating a new one.
Try the following code:
$event = $cal->events->get("[email protected]","longeventcodegivenbygoogle");
$event->setLocation('Somewhere');
$updated = $cal->events->update("[email protected]", $event->getId(), $event);
Upvotes: 4