Pankaj Agrawal
Pankaj Agrawal

Reputation: 1609

How to create events from google calendar API

I am working on a web application which is in PHP and javascript.In this application, we store some events in our own database.

Now, what we want is to whenever we create a new event in our app it should create a duplicate event on the Google calendar of the current logged in User's google calendar.

We can ask our users to generate an API key from their google console.

Is there any way to create a google calendar event via using an API key only and without any other configuration.

thanks

Upvotes: 0

Views: 3129

Answers (2)

Mr.Rebot
Mr.Rebot

Reputation: 6791

Unfortunately you have to use OAuth 2.0 for your app and not API key. Based on this documentation:

API keys

  • API keys should be used when API calls do not involve user data. This means the data returned for a request is the same regardless of the caller. APIs such as the Google Maps API and the Google Translation API use API keys.

Google authentication

  • Google authentication is favourable when all users have Google accounts. You may choose to use Google authentication, for example, if your API accompanies Google Apps (for example, a Google Drive companion).

Since you'll be accessing user's data you need to implement OAuth 2.0 authentication.

Additional reference:

Upvotes: 3

helpdoc
helpdoc

Reputation: 1990

Refer to the PHP quickstart on how to setup the environment:

https://developers.google.com/google-apps/calendar/quickstart/php

Change the scope to Google_Service_Calendar::CALENDAR and delete any stored

$event = new Google_Service_Calendar_Event(array(
  'summary' => 'Google I/O 2015',
  'location' => '800 Howard St., San Francisco, CA 94103',
  'description' => 'A chance to hear more about Google\'s developer products.',
  'start' => array(
    'dateTime' => '2015-05-28T09:00:00-07:00',
    'timeZone' => 'America/Los_Angeles',
  ),
  'end' => array(
    'dateTime' => '2015-05-28T17:00:00-07:00',
    'timeZone' => 'America/Los_Angeles',
  ),
  'recurrence' => array(
    'RRULE:FREQ=DAILY;COUNT=2'
  ),
  'attendees' => array(
    array('email' => '[email protected]'),
    array('email' => '[email protected]'),
  ),
  'reminders' => array(
    'useDefault' => FALSE,
    'overrides' => array(
      array('method' => 'email', 'minutes' => 24 * 60),
      array('method' => 'popup', 'minutes' => 10),
    ),
  ),
));

$calendarId = 'primary';
$event = $service->events->insert($calendarId, $event);
printf('Event created: %s\n', $event->htmlLink);

Upvotes: 0

Related Questions