简体   繁体   English

使用Java将Google日历数据(通过API v3)导入Google App Engine

[英]Importing Google Calendar data (via API v3) to Google App Engine with Java

I am in the process of writing a Java REST API for a reservation system where the event data comes Google Calendar (read-only). 我正在为预订系统编写Java REST API,其中事件数据来自Google Calendar(只读)。 I'm currently trying to figure out the best way to obtain and store the event data from Google Calendar in Google App Engine's JPA datastore. 我目前正在尝试找出在Google App Engine的JPA数据存储区中从Google日历获取和存储事件数据的最佳方法。 I also have a few requirements: 我也有一些要求:

  • I need to save the previous calendar data. 我需要保存以前的日历数据。 Simply dropping everything in the database and replacing it with new data will not suffice because I want to keep a historial view of the data for statistical purposes. 简单地删除数据库中的所有内容并用新数据替换它是不够的,因为我想保留数据的历史视图以用于统计目的。
  • I need to notify users when the event data changes, specifically for deletions. 我需要在事件数据发生变化时通知用户,特别是删除时。 This requires me to diff the new event data (from the API) with the old event data (from the JPA datastore). 这需要我使用旧的事件数据(来自JPA数据存储区)来区分新的事件数据(来自API)。

Does anyone have any general guidance and suggestions for what to do. 有没有人有什么一般指导和建议做什么。 Am I approaching the problem the correct way by attempting to duplicate the data into a datastore? 我是否尝试将数据复制到数据存储区中以正确的方式解决问题? Should I just make API requests every time I need to use the data? 我是否应该在每次需要使用数据时发出API请求? If I were do that, is there a way to kick off some mail service to notify users of event changes from directly within Google Calendar? 如果我这样做,有没有办法启动一些邮件服务,直接在Google日历中通知用户事件更改?

I think trying to replicate each event's information in the datastore will be suboptimal. 我认为尝试在数据存储区中复制每个事件的信息将是次优的。 If you want everything then you're going to end up storing a lot of data, and I suspect the majority of it will be of no use. 如果你想要一切,那么你最终会存储大量数据,我怀疑它的大部分都没用。

If you want to store data for statistical analysis, I'd suggest deciding what the minimal set of fields are that you wish to track, and just store those. 如果您想存储用于统计分析的数据,我建议您决定要跟踪的最小字段集,并存储这些字段。 A reasonable set of fields might be: event ID, name, time, attendees, location, description, and an internal version number for bookkeeping purposes. 一组合理的字段可能是:事件ID,名称,时间,与会者,位置,说明以及用于簿记目的的内部版本号。 Increment the version number each time a field changes, and you save the new field information. 每次字段更改时增加版本号,并保存新字段信息。 For extra credit, you can save a hash of the fields and not save new versions when the hash of the most recently retrieved entry matches what is already saved. 对于额外的功劳,您可以保存字段的哈希,而不是在最近检索的条目的哈希与已保存的条目匹配时保存新版本。

Since you're no longer storing the entire event on your server, the question of whether or not to query the API directly when you need event details is an obvious "yes". 由于您不再将整个事件存储在服务器上,因此在您需要事件详细信息时是否直接查询API的问题显然是“是”。

Google Calendar does provide email notifications when Calendar events are created or changed. Google Calendar会在创建或更改日历活动时提供电子邮件通知。 If you're concerned with users being notified about new events appearing on their calendars, this is easily taken care of by setting the sendNotifications field (in the call to insert a new event ) to true . 如果您担心用户会收到有关其日历上出现的新事件的通知,则可以通过将sendNotifications字段(在插入新事件的调用中)设置为true来轻松处理。 Similar functionality exists for update and delete calls in the API (and in the Calendar UI for when a user modifies an event). API中的更新和删除调用(以及用户修改事件时的日历UI中)存在类似的功能。

The most difficult part I see in this implementation is deciding how your application figures out when an event changes when a user makes a modification. 我在此实现中看到的最困难的部分是决定当用户进行修改时,当事件发生变化时应用程序如何计算出来。 (Changes made by your code can be immediately reflected in the data you keep in the datastore.) If all of the events appear on a single calendar, you can poll the API for a list of events , and use the updatedMin field with the time you last queried for updates. (您的代码所做的更改可以立即反映在您保存在数据存储区中的数据中。)如果所有事件都显示在单个日历上,您可以轮询API以获取事件列表 ,并将updatedMin字段与时间一起使用你上次询问更新。 If the events are on multiple calendars, the approach is the same, but you'll need to do one list per calendar. 如果事件在多个日历上,则方法相同,但您需要为每个日历执行一个列表。

Note that whatever credentials you supply to your application will need to be able to read and write to whatever calendar(s) you are modifying. 请注意,您提供给应用程序的任何凭据都需要能够读取和写入您正在修改的日历。 As an initial approach, I'd suggest you create a master calendar for your application that is listed as an attendee on all of the events you are tracking. 作为初始方法,我建议您为应用程序创建一个主日历,该日历作为您正在跟踪的所有事件的与会者列出。 Events you create on behalf of users will list the users as attendees. 您代表用户创建的事件会将用户列为与会者。 Events users create and wish to associate with your application will need to add the master calendar as an attendee. 用户创建并希望与您的应用程序关联的事件需要将主日历添加为与会者。 This last point may require administrative users get some training in the correct way to interact with the system. 最后一点可能要求管理用户以正确的方式与系统进行交互。

The alternative to the above is to have all users delegate access to their calendar to your application, but you will have to manage multiple sets of credentials and possibly weed out any events on users' calendars that you are not interested in tracking. 上述方法的替代方法是让所有用户将对其日历的访问权限委托给您的应用程序,但您必须管理多组凭据,并且可能会清除您不想跟踪的用户日历上的任何事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM