Reputation: 1382
I am getting a issue when I remove a event from my application (even from google calendar too). I have my calendar with all my events, I try to remove a event for first time, and it "works": I change the tab of my browser, and see the Google Calendar panel and the event had successfully removed, great!! BUT, if I reload the tab of my application... I still see the event!!!
Also, if I remove the data from the Google Calendar Panel, the application still recover this event on the API call:
$service->events->listEvents($calendar,$eventsParam);
$service is a Google_Service_Calendar object.
Thank you.
EDIT
This is the way how I delete the events:
public function removedate()
{
$service = getService();
$service->events->delete($this->input->post("calendar"), getEventId($service));
}
I am working with codeigniter and I am using a helper made by myself for the most habitual functions, between them these two:
function getService($file=false)
{
$ci =& get_instance();
if($file)
$file = CREDENTIALS_PATH.$file;
else
$file = CREDENTIALS_PATH.$ci->session->userdata("identity").".json";
$ci->g_client->setAccessToken(file_get_contents($file));
return new Google_Service_Calendar($ci->g_client);
}
function getEventId($service)
{
$ci =& get_instance();
$id = $ci->input->post("id");
$dni = $id;
if(!is_numeric($id))
$id = $ci->general_model->getData("users","phone", array("dni"=>$id), true)->phone;
$min = false;
$max = false;
if($ci->input->post("min"))
$min = date("c", strtotime ( '-2 hour' , strtotime ( (new DateTime(explode("GMT", $ci->input->post("min"))[0]))->format("c"))));
if($ci->input->post("max"))
$max = (new DateTime(explode("GMT", $ci->input->post("max"))[0]))->format("c");
$events = getDates($service, $ci->input->post("calendar"), $min, $max);
foreach ($events->getItems() as $event)
{
if($id==$event->getSummary() || $dni==$event->getSummary())
return $event->getId();
}
}
NEW EDIT
One more thing... when I remove a event for first time there is no problem (and the event is DELETED on the google calendar), and when I refresh my app page the event still remains, and when I try to delete it again I get this error:
<br />
<b>Fatal error</b>: Uncaught exception 'Google_Service_Exception' with message 'Error calling DELETE
https://www.googleapis.com/calendar/v3/calendars/cnhkehagcve7rm8s1g88hauer8%40group.calendar.google.com/events/97smpf2320s3lmg8nnnpb9dndc: (410)
Resource has been deleted' in
/var/www/html/prototipo/application/third_party/vendor/google/apiclient/src/Google/Http/REST.php:110
RESOURCE HAS BEEN DELETED... Yes!!! I know!!! why does it remain??????
Upvotes: 1
Views: 684
Reputation: 421
To get all events
$events = $service->events->listEvents('<calendar_id>');
To remove any event from calendar
$result = $service->events->delete('<calendar_id>', '<event_id>');
echo "<br>========================<br>";
var_dump($result);
echo "<br>========================<br>";
Upvotes: 1