Want to create Google Clanedar event which repeats yearly - php

I successfully managed to add event to google calendar through php api client, but what i want is to make that event repeat every year , such as company anniversay etc, i didn't find that in the google documentation also ,so what should be added while creating event for repeatation

There is documentation for recurring event
$event = new Google_Service_Calendar_Event();
$event->setSummary('Appointment');
$event->setLocation('Somewhere');
$start = new Google_Service_Calendar_EventDateTime();
$start->setDateTime('2011-06-03T10:00:00.000-07:00');
$start->setTimeZone('America/Los_Angeles');
$event->setStart($start);
$end = new Google_Service_Calendar_EventDateTime();
$end->setDateTime('2011-06-03T10:25:00.000-07:00');
$end->setTimeZone('America/Los_Angeles');
$event->setEnd($end);
$event->setRecurrence(array('RRULE:FREQ=YEARLY;UNTIL=20110701T170000Z'));
$attendee1 = new Google_Service_Calendar_EventAttendee();
$attendee1->setEmail('attendeeEmail');
// ...
$attendees = array($attendee1,
// ...
);
$event->attendees = $attendees;
$recurringEvent = $service->events->insert('primary', $event);
echo $recurringEvent->getId();

Related

How to insert event into a private Google Calendar with PHP?

I'm trying to add new events into my private Google Calendar, but I get (403) Forbidden message. I've searched the internet but I found no answer to my issue.
My scope is set to read/write, and the credentials should be ok, because I can read out all of my events so the connection works fine.
Here's the code:
$service_account = $this->service_account;
$json_key = json_decode(file_get_contents($this->json_url));
$scopes = 'https://www.googleapis.com/auth/calendar';
$application_name = 'Calendar';
$client = new Google_Client();
$client->setApplicationName($application_name);
$cred = new Google_Auth_AssertionCredentials($service_account, array($scopes), $json_key->private_key);
$client->setAssertionCredentials($cred);
if($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($cred);
}
$google_service = new Google_Service_Calendar($client);
$calendar_ids = $this->calendar_ids;
$event = new Google_Service_Calendar_Event();
$event->setSummary($service);
$event->setDescription($user);
$event->setLocation($location);
$start = new Google_Service_Calendar_EventDateTime();
$start->setDateTime($this->sqlDateToGcalDate($start_date));
$event->setStart($start);
$end = new Google_Service_Calendar_EventDateTime();
$end->setDateTime($this->sqlDateToGcalDate($end_date));
$event->setEnd($end);
$google_service->events->insert($calendar_ids[$steed], $event);
$google_service->events->insert($calendar_ids[$location], $event);

How to add an event to another persons calendar using google calendar api?

i am trying to add a event to a particular person's calendar ,
the person is decided based on html form the value is stored in send
The mail is sent but event is not set.
this is my php code..
<?php
require_once 'google-api-php-client-master/autoload.php';
require_once 'google-api-php-client-master/src/Google/Service/Calendar.php';
$client = new Google_Client();
// OAuth2 client ID and secret can be found in the Google Developers Console.
$client->setClientId('######.apps.googleusercontent.com');
$client->setClientSecret('###');
$client->setRedirectUri('https://www.example.com/oauth2callback');
$client->addScope('https://www.googleapis.com/auth/calendar');
$send = $_POST["to"];
echo "Welcome $send successfully set an event in your calendar";
if( $send == "abc")
{
$to = "abc#gmail.com";
$subject = "Sample Mail Project";
$txt = $_POST["txt"];
$headers = "From: xyz#gmail.com" . "\r\n" ;
mail($to,$subject,$txt,$headers);
$event = new Google_Service_Calendar_EventDateTime();
$event->setSummary('Appointment');
$event->setLocation('VIZAG');
$start = new Google_Service_Calendar_Event();
$start->setDateTime('2014-12-19T06:00:00');
$event->setStart($start);
$start = new Google_Service_Calendar_Event();
$end->setDateTime('2014-12-19T10:10:00');
$event->setEnd($end);
$attendee1 = new EventAttendee();
$attendee1->setEmail('abc#gmail.com');
// ...
$attendees = array($attendee1
// ...
);
$event->attendees = $attendees;
$createdEvent = $service->events->insert('primary', $event);
echo $createdEvent->getId();
}
According to the documentation you should do an event insert this way:
$event = new Google_Service_Calendar_Event();
$event->setSummary('Appointment');
$event->setLocation('Somewhere');
$start = new Google_Service_Calendar_EventDateTime();
$start->setDateTime('2011-06-03T10:00:00.000-07:00');
$event->setStart($start);
$end = new Google_Service_Calendar_EventDateTime();
$end->setDateTime('2011-06-03T10:25:00.000-07:00');
$event->setEnd($end);
$attendee1 = new Google_Service_Calendar_EventAttendee();
$attendee1->setEmail('attendeeEmail');
// ...
$attendees = array($attendee1,
// ...
);
$event->attendees = $attendees;
$createdEvent = $service->events->insert('primary', $event);
Or you can do it with the quickAdd() method:
$createdEvent = $service->events->quickAdd(
'primary',
'Appointment at Somewhere on June 3rd 10am-10:25am'
);

How to update google calendar event datetime using API V3

I can successfully update the title of the events using Google API V3, but once I include the datetime, I get internal server error. Here's the snippet of my code:
$event = $service->events->get($calendar_id,$event_id);
$event->setSummary($notes);
$service->events->update($calendar_id,$event->getId(),$event);
The above code works well since I'm only updating the title. I'm struggling with the code below:
$event = $service->events->get($calendar_id,$event_id);
$event->setSummary($notes);
$start = new Google_Service_Calendar_EventDateTime();
$start->setDateTime('2014-07-22T20:00:00+08:00');
$event->setStart($start);
$end = new Google_Service_Calendar_EventDateTime();
$end->setDateTime('2014-07-22T21:00:00+08:00');
$event->setEnd($end);
$service->events->update($calendar_id,$event->getId(),$event);
I'm not sure if I have the correct format for the datetime. Any advice? Thanks!
// Cambio de fecha de evento
$end = new Google_Service_Calendar_EventDateTime();
$end->setDateTime('2021-09-01T14:00:00');
$end->setTimeZone('America/Mexico_City');
$event->setEnd($end);
$Start = new Google_Service_Calendar_EventDateTime();
$Start->setDateTime('2021-09-01T12:00:00');
$Start->setTimeZone('America/Mexico_City');
$event->setStart($Start);
$updatedEvent = $service->events->update(CalendarID, $event->getId(), $event);
You probably want to do $event->setEnd($end); instead of $event->setStart($end);

Google Calendar PHP API, what am I doing wrong?

<?php
session_start();
require_once "Google/Client.php";
require_once "Google/Service/Calendar.php";
$apiClient = new Google_Client();
$apiClient->setApplicationName("My Application");
$apiClient->setDeveloperKey("API_KEY");
$service = new Google_Service_Calendar($apiClient);
$event = new Google_Service_Calendar_Event();
$event->setSummary('Appointment');
$event->setLocation('Somewhere');
$start = new Google_Service_Calendar_EventDateTime();
$start->setDateTime('2011-06-03T10:00:00.000-07:00');
$start->setTimeZone('America/Los_Angeles');
$event->setStart($start);
$end = new Google_Service_Calendar_EventDateTime();
$end->setDateTime('2011-06-03T10:25:00.000-07:00');
$end->setTimeZone('America/Los_Angeles');
$event->setEnd($end);
$attendee1 = new Google_Service_Calendar_EventAttendee();
$attendee1->setEmail('EMAIL');
$attendees = array($attendee1,
// ...
);
$event->setAttendees($attendees);
$recurringEvent = $service->events->insert('primary', $event);
echo $recurringEvent->getId();
?>
Everything compiles correctly until I execute $service->events->insert? am I authenticating wrong? I have been trying this for days. Alls I'm trying to do is simply authenticate, and create a calendar event. (I don't need multi-user auth, just one admin user).
Help is appreciated!

Set google event reminders with api for Google Calendar from php

i have a script php for creating a google calendar event.
the script work correctly but the function to set the date wrong.
the script his
[...initial statements...]
$event = new Google_Event();
$event->setSummary("test");
$event->setLocation("location");
$start = new Google_EventDateTime();
$start->setDateTime(2014-05-01T10:00:00.000-07:00);
$event->setStart($start);
$end = new Google_EventDateTime();
$end->setDateTime(2014-05-01T10:00:00.000-08:00);
$event->setEnd($end);
$reminder = new Google_EventReminders();
$reminder->setUseDefault(false);
$overrides = array("method"=> "popup","minutes" => "15");
$reminder->setOverrides(array($overrides));
$event->setReminders($reminder);
$createdEvent = $service->events->insert('primary', $event);
[...]
in event created i ha have two reminders
email 10 minutes and popup 10 minutes
Here is how I got mine to work :)
$event = new Google_Event(); //note in the API examples it calls Event(). Apparently, they changed it and didn't update examples.
$event->setSummary($task);
$event->setColorId('4');
$event->setDescription($type);
$event->setLocation($type);
$start = new Google_EventDateTime(); //note in the API examples it calls EventDateTime().
$start->setDateTime($date1);
$event->setStart($start);
$end = new Google_EventDateTime(); //note in the API examples it calls EventDateTime().
$end->setDateTime($date2);
$event->setEnd($end);
$attendee1 = new Google_EventAttendee(); //note in the API examples it calls EventAttendee().
$attendee1->setEmail('myemail#gmail.com'); //make sure you actually put an email address in here
$reminderI = new Google_EventReminder();
$reminderI->setMethod('email');
$reminderI->setMinutes('25');
$reminder = new Google_EventReminders();
$reminder->setUseDefault('false');
$reminder->setOverrides(array($reminderI));
$event->setReminders($reminder);
I spent a few minutes and figure it out, try this:
$reminders = new Google_Service_Calendar_EventReminders();
$reminders->setUseDefault(false);
$reminder = new Google_Service_Calendar_EventReminder();
$method = empty($v['method']) ? 'email' : $v['method'];
$minute = empty($v['minute']) ? '10' : $v['minute'];
$reminder->setMethod($method);
$reminder->setMinutes($minute);
$reminders->setOverrides(array($reminder));
$targetEvent->setReminders($reminders);
Notice here $reminders->setOverrides(array($reminder)); we need to put the $reminder in an array while calling $reminders->setOverrides
I am using the API V3, and I guess you're using V2. Anyway, it should be quite similar.
Hope this helps.
I think the problem is here:
$overrides = array("method"=> "popup","minutes" => "15");
You are essentially wrapping an array inside an array in here:
setOverrides(array($overrides));
The override should instead be an object of type Google_Service_Calendar_EventReminder.

Categories