Home » Php » Google Calendar sync with php in 2 ways

Google Calendar sync with php in 2 ways

Posted by: admin July 12, 2020 Leave a comment

Questions:

I am creating a php website that uses the Google Calendar API. It’s working fine with Create, Update and Delete: any event from the PHP website goes into my Google Calendar events after login.

Events created on my site are created in Google Calendar.

What I want now that is: when I create an event from my test page it goes into Google Calendar after login, then if I update or delete that event from Google Calendar then it should automatically update or delete the php website event.

Basically: 1-way sync is working fine but now I want 2-way synchronization.

If anybody has any ideas then kindly share with me, it will be much appreciated.

How to&Answers:

There are no application hooks in Google Calendar (gCal) that allow you to trigger an action when an event is deleted. Instead you must either poll gCal at intervals (this could be a cron job every few minutes/hours) and update your calendar accordingly, or any time you perform an action from your calendar have a 1 in X possibly of a full re-sync.

This implies that you are using the gCal as the definitive source, and mirroring those changes back to your local application.

Answer:

well, after following these answers and building a hole 2 way sync process,
i realized there’s a push notifications for calendar since 2013.
you will still need a full sync process because the push notification only notifies about a change but no data about the change.
hope it will save you some time.

Push Notifications

Answer:

Would it not be an option for your system to generate an iCal output at a special, user-specific URL, and then have the user subscribe to that calendar in Google Calendars (or their iCal-reading calendar of choice)?

That way, your system would always hold the authorative calendar, and Google Calendar would reflect any changes you make automatically.

Alternately, if you are wanting changes in the Google Calendar to be reflected in your application, then you may be able to subscribe to iCals for the User’s Calendar, and then poll them at a regular interval to reflect any changes the User has made at that end.

I would lean towards the first option (your iCal subscribed through Google Calendar), as it is a simpler and easier solution.