ユーザーは Google カレンダーの予定を自由に更新、削除できます。ユーザーが 会議を作成した後に予定を更新する場合、アドオンは 変更に対応するために会議データを更新します。お使いの イベントデータの追跡に依存していますが、 イベント変更時に会議を更新できないと、会議が ユーザーエクスペリエンスの低下につながります
インフラストラクチャの変更に合わせて会議データを最新の状態に維持するプロセスは、 Google カレンダーの予定は同期と呼ばれます。イベントの変更は、次の方法で同期できます。 Apps Script を作成する 起動するインストール可能なトリガー 予定が変更されるたびに通知を受け取れます。残念ながら、トリガーは 変更されたイベントをレポートに表示でき、 共有します。代わりに、サービス アカウントのリストをリクエストし、 前回の同期以降にカレンダーに加えられたすべての変更を 必要に応じて更新してください
一般的な同期手順は次のとおりです。
- ユーザーが初めて会議を作成すると、同期プロセスが初期化されます。
- ユーザーがカレンダーの予定を作成、更新、削除したとき トリガーがアドオン プロジェクトのトリガー関数を実行します。
- トリガー関数は、前回のイベント以降の一連のイベント変更を 関連するサードパーティ アプリの更新が 可能です。
- 必要な更新は、サードパーティのパートナーに API リクエスト。
- 新しい同期トークンが保存されるため、次のトリガーの実行に必要なのは、 カレンダーの最新の変更内容を確認する。
同期を初期化する
アドオンによってサードパーティ製システムで会議が作成されると、 インストール可能なトリガーが作成されるはずです。 レスポンスが イベントの変更 このカレンダーに表示されます。
トリガーの作成後、最初のトリガーを作成して初期化を完了します。 できます。これを行うには、トリガー関数を直接実行します。
Calendar トリガーを作成する
カレンダーの予定が添付された日時をアドオンが検出し、
変更されます。そのためには、EventUpdated
インストール可能なトリガー。アドオン
トリガーはカレンダーごとに 1 つのみで、プログラムで作成できます。
トリガーを作成するのは、ユーザーが最初の会議を作成するときです。 ユーザーがその時点からアドオンを使い始めるためです。変更後 会議を作成したり エラーがないことを確認したら、アドオンは トリガーが存在し、存在しない場合は作成してください。
同期トリガー関数を実装する
トリガー関数は、Apps Script が原因となる条件を
発生します
EventUpdated
カレンダーのトリガー
指定したイベントのイベントをユーザーが作成、変更、削除されたときに起動されます。
カレンダー。
アドオンで使用するトリガー関数を実装する必要があります。このトリガー関数は 次のようにする必要があります。
- カレンダー拡張サービスの
Calendar.Events.list()
を呼び出すsyncToken
を使用して、前回の日時以降に変更されたイベントのリストを取得 同期できます。同期トークンを使用することで、アドオンが送信するイベントの数を減らすことができる 調べる必要があります。有効な同期トークンなしでトリガー関数が実行されると、 完全同期になります。完全同期では、すべてのイベントの取得が試行されるだけです。 新しい有効な同期を生成するために、一定の時間内に あります。
- 変更された各イベントが調べられ、関連するイベントがあるかどうかが 行うこともできます。
- 予定に会議がある場合は、変更の内容が確認されます。 変更によっては、関連する会議の変更によって できます。たとえば、予定が削除された場合、アドオンは その会議を削除することが考えられます。
- 会議に必要な変更は、API 呼び出しによって アクセスします。
- 必要な変更をすべて行ったら、
nextSyncToken
Calendar.Events.list()
メソッド。この同期トークンは最後にCalendar.Events.list()
呼び出しによって返された結果のページ。
Google カレンダーの予定を更新する
会議中に Google カレンダーの予定を更新したい場合があります。
行われます。これを行う場合は、
Google カレンダー拡張サービス
リクエストできます。必ず
条件付き更新
(If-Match
ヘッダー付き)。これにより、不注意による変更による
別のクライアントでユーザーが同時に行った変更を上書きする。
例
次の例は、カレンダーの予定の同期を設定する方法を示しています。 会議の詳細を確認できます。
/** * Initializes syncing of conference data by creating a sync trigger and * sync token if either does not exist yet. * * @param {String} calendarId The ID of the Google Calendar. */ function initializeSyncing(calendarId) { // Create a syncing trigger if it doesn't exist yet. createSyncTrigger(calendarId); // Perform an event sync to create the initial sync token. syncEvents({'calendarId': calendarId}); } /** * Creates a sync trigger if it does not exist yet. * * @param {String} calendarId The ID of the Google Calendar. */ function createSyncTrigger(calendarId) { // Check to see if the trigger already exists; if does, return. var allTriggers = ScriptApp.getProjectTriggers(); for (var i = 0; i < allTriggers.length; i++) { var trigger = allTriggers[i]; if (trigger.getTriggerSourceId() == calendarId) { return; } } // Trigger does not exist, so create it. The trigger calls the // 'syncEvents()' trigger function when it fires. var trigger = ScriptApp.newTrigger('syncEvents') .forUserCalendar(calendarId) .onEventUpdated() .create(); } /** * Sync events for the given calendar; this is the syncing trigger * function. If a sync token already exists, this retrieves all events * that have been modified since the last sync, then checks each to see * if an associated conference needs to be updated and makes any required * changes. If the sync token does not exist or is invalid, this * retrieves future events modified in the last 24 hours instead. In * either case, a new sync token is created and stored. * * @param {Object} e If called by a event updated trigger, this object * contains the Google Calendar ID, authorization mode, and * calling trigger ID. Only the calendar ID is actually used here, * however. */ function syncEvents(e) { var calendarId = e.calendarId; var properties = PropertiesService.getUserProperties(); var syncToken = properties.getProperty('syncToken'); var options; if (syncToken) { // There's an existing sync token, so configure the following event // retrieval request to only get events that have been modified // since the last sync. options = { syncToken: syncToken }; } else { // No sync token, so configure to do a 'full' sync instead. In this // example only recently updated events are retrieved in a full sync. // A larger time window can be examined during a full sync, but this // slows down the script execution. Consider the trade-offs while // designing your add-on. var now = new Date(); var yesterday = new Date(); yesterday.setDate(now.getDate() - 1); options = { timeMin: now.toISOString(), // Events that start after now... updatedMin: yesterday.toISOString(), // ...and were modified recently maxResults: 50, // Max. number of results per page of responses orderBy: 'updated' } } // Examine the list of updated events since last sync (or all events // modified after yesterday if the sync token is missing or invalid), and // update any associated conferences as required. var events; var pageToken; do { try { options.pageToken = pageToken; events = Calendar.Events.list(calendarId, options); } catch (err) { // Check to see if the sync token was invalidated by the server; // if so, perform a full sync instead. if (err.message === "Sync token is no longer valid, a full sync is required.") { properties.deleteProperty('syncToken'); syncEvents(e); return; } else { throw new Error(err.message); } } // Read through the list of returned events looking for conferences // to update. if (events.items && events.items.length > 0) { for (var i = 0; i < events.items.length; i++) { var calEvent = events.items[i]; // Check to see if there is a record of this event has a // conference that needs updating. if (eventHasConference(calEvent)) { updateConference(calEvent, calEvent.conferenceData.conferenceId); } } } pageToken = events.nextPageToken; } while (pageToken); // Record the new sync token. if (events.nextSyncToken) { properties.setProperty('syncToken', events.nextSyncToken); } } /** * Returns true if the specified event has an associated conference * of the type managed by this add-on; retuns false otherwise. * * @param {Object} calEvent The Google Calendar event object, as defined by * the Calendar API. * @return {boolean} */ function eventHasConference(calEvent) { var name = calEvent.conferenceData.conferenceSolution.name || null; // This version checks if the conference data solution name matches the // one of the solution names used by the add-on. Alternatively you could // check the solution's entry point URIs or other solution-specific // information. if (name) { if (name === "My Web Conference" || name === "My Recorded Web Conference") { return true; } } return false; } /** * Update a conference based on new Google Calendar event information. * The exact implementation of this function is highly dependant on the * details of the third-party conferencing system, so only a rough outline * is shown here. * * @param {Object} calEvent The Google Calendar event object, as defined by * the Calendar API. * @param {String} conferenceId The ID used to identify the conference on * the third-party conferencing system. */ function updateConference(calEvent, conferenceId) { // Check edge case: the event was cancelled if (calEvent.status === 'cancelled' || eventHasConference(calEvent)) { // Use the third-party API to delete the conference too. } else { // Extract any necessary information from the event object, then // make the appropriate third-party API requests to update the // conference with that information. } }