如何从 google 日历 API 创建活动

How to create events from google calendar API

我正在开发 PHP 和 javascript.In 这个应用程序中的 Web 应用程序,我们将一些事件存储在我们自己的数据库中。

现在,我们想要的是每当我们在我们的应用程序中创建一个新事件时它应该 在当前登录用户 google 日历的 Google 日历上创建重复事件。

我们可以要求我们的用户从他们的 google 控制台生成一个 API 密钥。

是否可以通过仅使用 API 键而不使用任何其他配置来创建 google 日历事件。

感谢

请参阅 PHP 快速入门了解如何设置环境:

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

将范围更改为 Google_Service_Calendar::CALENDAR 并删除所有已存储的

$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' => 'lpage@example.com'),
    array('email' => 'sbrin@example.com'),
  ),
  '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);

很遗憾,您的应用程序必须使用 OAuth 2.0 而不是 API 密钥。基于此 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).

由于您将访问用户数据,因此您需要实施 OAuth 2.0 身份验证。

附加参考: