[英]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. 我正在使用PHP和javascript编写Web应用程序。在此应用程序中,我们将一些事件存储在我们自己的数据库中。
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. 现在,我们想要的是,每当我们在应用程序中创建一个新事件时,它都应该在当前登录用户的Google日历的Google日历上创建一个重复事件。
We can ask our users to generate an API key from their google console. 我们可以要求用户从其Google控制台生成API密钥。
Is there any way to create a google calendar event via using an API key only and without any other configuration. 有什么方法可以仅通过使用API密钥而无需任何其他配置来创建Google日历事件。
thanks 谢谢
Unfortunately you have to use OAuth 2.0 for your app and not API key. 不幸的是,您必须为您的应用使用OAuth 2.0,而不是API密钥。 Based on this documentation : 根据此文档 :
API keys API密钥
- API keys should be used when API calls do not involve user data. 当API调用不涉及用户数据时,应使用API密钥。 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 Maps API和Google Translation API之类的API使用API密钥。
Google authentication Google认证
- Google authentication is favourable when all users have Google accounts. 当所有用户都拥有Google帐户时,使用Google身份验证是有利的。 You may choose to use Google authentication, for example, if your API accompanies Google Apps (for example, a Google Drive companion). 例如,如果您的API随附于Google Apps(例如Google Drive伴侣),则您可以选择使用Google身份验证。
Since you'll be accessing user's data you need to implement OAuth 2.0 authentication. 由于您将访问用户的数据,因此需要实现OAuth 2.0身份验证。
Additional reference: 附加参考:
Refer to the PHP quickstart on how to setup the environment: 有关如何设置环境,请参考PHP快速入门:
https://developers.google.com/google-apps/calendar/quickstart/php https://developers.google.com/google-apps/calendar/quickstart/php
Change the scope to Google_Service_Calendar::CALENDAR and delete any stored 将范围更改为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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.