Home » Android » How to add event on google calendar using calendar API using android?

How to add event on google calendar using calendar API using android?

Posted by: admin June 15, 2020 Leave a comment


Hi I am trying to create an event in Google calendar using Google calendar API in android.

I have created a sample project provided by Google, and I followed the each steps and compiled the project successfully.

But in this Example of Google calendar, I can only create a calendar name to my Google calendar account, I can’t create any event.

Is there any way to create an event in Google calendar? If so how can I do it?

How to&Answers:

After Searching for some time i have finally find the solution .the answer was in the google document it self just go through this link

it shows how to create an event using google calender api.


This is such a giant pain in the ass – but I finally got it working for creating events at least.

Download the most recent Google PHP API zip, and upload it to your includes folder on your webserver. Use Google API Console to set up an API client. Make sure you set your redirect url to be the same as your page’s url – so it redirects to its self.

I’ve initially just set some variables for event details, you can make a form which shoves these in if you want.

Here’s my code:

    $jobname = "BINGO";
    $joblocation = "Your mums house";
    $jobdescription = "An interview with a dog.";
    $startofjob = "2013-12-20T17:00:00.000+00:00"; //datetimes must be in this format
    $endofjob = "2013-12-20T18:00:00.000+00:00"; // YYYY-MM-DDTHH:MM:SS.MMM+HH:MM
    //So that's year, month, day, the letter T, hours, minutes, seconds, miliseconds, + or -, timezoneoffset in hours and minutes



    $client = new Google_Client();
    $cal = new Google_CalendarService($client);

    if (isset($_GET['code'])) {
      $_SESSION['token'] = $client->getAccessToken();
      header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);

    if (isset($_SESSION['token'])) {

    if ($client->getAccessToken()) {
      $event = new Google_Event();
    $start = new Google_EventDateTime();
    $end = new Google_EventDateTime();

    $createdEvent = $cal->events->insert('[email protected]', $event);
    echo $createdEvent->id;

    $_SESSION['token'] = $client->getAccessToken();
    } else {
      $authUrl = $client->createAuthUrl();
      print "<a class='login' href='$authUrl'>Connect Me!</a>";