イベントを作成する

ユーザーが最適なハイキング ルートを見つけるのに役立つアプリについて考えてみましょう。次のように ハイキング プランをカレンダーの予定として組み込むと、 自動的に整理されます。Google カレンダーは、計画を共有し、 ストレスなく準備できるように、そのことを思い出させます。また シームレスな統合を実現するため Google マップが時間どおりにミーティングの場所を案内します。

この記事では、カレンダーの予定を作成してユーザーの できます。

予定を追加

イベントを作成するには、 events.insert() メソッド: 少なくとも次のパラメータを指定します

  • calendarId は、カレンダー ID で、メールアドレスのいずれかです。 予定を作成するカレンダーの名前または 'primary': ログイン ユーザーのメイン カレンダーを使用します。条件 使用するカレンダーのメールアドレスがわからない場合、 ウェブ版の Google カレンダーのカレンダーの設定で、 UI([カレンダーのアドレス] セクション内)、または 結果に calendarList.list() 呼び出し。
  • event は、開始などの必要な詳細情報をすべて指定して作成するイベントです。 あります必須フィールドは、startend の 2 つだけです。詳しくは、 イベントの完全なセットの event リファレンス 表示されます。

イベントを正常に作成するには、以下を行う必要があります。

  • OAuth スコープを https://www.googleapis.com/auth/calendar に設定し、 そのユーザーのカレンダーの編集権限がある。
  • 認証済みのユーザーが 指定した calendarIdcalendarList.get(): calendarIdaccessRole を確認します)。

イベント メタデータを追加する

必要に応じて、カレンダーの予定の作成時にイベントのメタデータを追加できます。もし 作成時にメタデータを追加しない場合は、 events.update();一部のフィールドは (例: イベント ID など)は、Chronicle の events.insert() オペレーション。

場所

場所の項目に住所を追加すると、次のような機能が利用できるようになります。

「出発時間」経路の地図を表示する場合などです。

イベント ID

イベントの作成時に、独自のイベント ID を生成するように選択できます。

画像アセットを追加します。これにより、エンティティを Google カレンダーの予定と同期できます。また、 オペレーションが失敗した場合に、重複イベントの作成を防止 カレンダー バックエンドで正常に実行されます。「いいえ」の場合 イベント ID が提供されると、サーバーによって生成されます。イベント ID を確認する リファレンスをご覧ください。

参加者

作成した予定は、組織内のすべてのメインの Google カレンダーに表示されます。

同じ予定 ID の参加者に表示されます。次の値を設定した場合: 挿入リクエストで sendNotificationstrue にした場合、参加者は イベントに関するメール通知も受け取ります。詳しくは、 複数の参加者に ご確認ください。

次の例は、イベントを作成してそのメタデータを設定する方法を示しています。

Go

// Refer to the Go quickstart on how to setup the environment:
// https://developers.google.com/calendar/quickstart/go
// Change the scope to calendar.CalendarScope and delete any stored credentials.

event := &calendar.Event{
  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: &calendar.EventDateTime{
    DateTime: "2015-05-28T09:00:00-07:00",
    TimeZone: "America/Los_Angeles",
  },
  End: &calendar.EventDateTime{
    DateTime: "2015-05-28T17:00:00-07:00",
    TimeZone: "America/Los_Angeles",
  },
  Recurrence: []string{"RRULE:FREQ=DAILY;COUNT=2"},
  Attendees: []*calendar.EventAttendee{
    &calendar.EventAttendee{Email:"lpage@example.com"},
    &calendar.EventAttendee{Email:"sbrin@example.com"},
  },
}

calendarId := "primary"
event, err = srv.Events.Insert(calendarId, event).Do()
if err != nil {
  log.Fatalf("Unable to create event. %v\n", err)
}
fmt.Printf("Event created: %s\n", event.HtmlLink)

Java

// Refer to the Java quickstart on how to setup the environment:
// https://developers.google.com/calendar/quickstart/java
// Change the scope to CalendarScopes.CALENDAR and delete any stored
// credentials.

Event event = new Event()
    .setSummary("Google I/O 2015")
    .setLocation("800 Howard St., San Francisco, CA 94103")
    .setDescription("A chance to hear more about Google's developer products.");

DateTime startDateTime = new DateTime("2015-05-28T09:00:00-07:00");
EventDateTime start = new EventDateTime()
    .setDateTime(startDateTime)
    .setTimeZone("America/Los_Angeles");
event.setStart(start);

DateTime endDateTime = new DateTime("2015-05-28T17:00:00-07:00");
EventDateTime end = new EventDateTime()
    .setDateTime(endDateTime)
    .setTimeZone("America/Los_Angeles");
event.setEnd(end);

String[] recurrence = new String[] {"RRULE:FREQ=DAILY;COUNT=2"};
event.setRecurrence(Arrays.asList(recurrence));

EventAttendee[] attendees = new EventAttendee[] {
    new EventAttendee().setEmail("lpage@example.com"),
    new EventAttendee().setEmail("sbrin@example.com"),
};
event.setAttendees(Arrays.asList(attendees));

EventReminder[] reminderOverrides = new EventReminder[] {
    new EventReminder().setMethod("email").setMinutes(24 * 60),
    new EventReminder().setMethod("popup").setMinutes(10),
};
Event.Reminders reminders = new Event.Reminders()
    .setUseDefault(false)
    .setOverrides(Arrays.asList(reminderOverrides));
event.setReminders(reminders);

String calendarId = "primary";
event = service.events().insert(calendarId, event).execute();
System.out.printf("Event created: %s\n", event.getHtmlLink());

JavaScript

// Refer to the JavaScript quickstart on how to setup the environment:
// https://developers.google.com/calendar/quickstart/js
// Change the scope to 'https://www.googleapis.com/auth/calendar' and delete any
// stored credentials.

const event = {
  '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': {
    'dateTime': '2015-05-28T09:00:00-07:00',
    'timeZone': 'America/Los_Angeles'
  },
  'end': {
    'dateTime': '2015-05-28T17:00:00-07:00',
    'timeZone': 'America/Los_Angeles'
  },
  'recurrence': [
    'RRULE:FREQ=DAILY;COUNT=2'
  ],
  'attendees': [
    {'email': 'lpage@example.com'},
    {'email': 'sbrin@example.com'}
  ],
  'reminders': {
    'useDefault': false,
    'overrides': [
      {'method': 'email', 'minutes': 24 * 60},
      {'method': 'popup', 'minutes': 10}
    ]
  }
};

const request = gapi.client.calendar.events.insert({
  'calendarId': 'primary',
  'resource': event
});

request.execute(function(event) {
  appendPre('Event created: ' + event.htmlLink);
});

Node.js

// Refer to the Node.js quickstart on how to setup the environment:
// https://developers.google.com/calendar/quickstart/node
// Change the scope to 'https://www.googleapis.com/auth/calendar' and delete any
// stored credentials.

const event = {
  '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': {
    'dateTime': '2015-05-28T09:00:00-07:00',
    'timeZone': 'America/Los_Angeles',
  },
  'end': {
    'dateTime': '2015-05-28T17:00:00-07:00',
    'timeZone': 'America/Los_Angeles',
  },
  'recurrence': [
    'RRULE:FREQ=DAILY;COUNT=2'
  ],
  'attendees': [
    {'email': 'lpage@example.com'},
    {'email': 'sbrin@example.com'},
  ],
  'reminders': {
    'useDefault': false,
    'overrides': [
      {'method': 'email', 'minutes': 24 * 60},
      {'method': 'popup', 'minutes': 10},
    ],
  },
};

calendar.events.insert({
  auth: auth,
  calendarId: 'primary',
  resource: event,
}, function(err, event) {
  if (err) {
    console.log('There was an error contacting the Calendar service: ' + err);
    return;
  }
  console.log('Event created: %s', event.htmlLink);
});

PHP

$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);

Python

# Refer to the Python quickstart on how to setup the environment:
# https://developers.google.com/calendar/quickstart/python
# Change the scope to 'https://www.googleapis.com/auth/calendar' and delete any
# stored credentials.

event = {
  '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': {
    'dateTime': '2015-05-28T09:00:00-07:00',
    'timeZone': 'America/Los_Angeles',
  },
  'end': {
    'dateTime': '2015-05-28T17:00:00-07:00',
    'timeZone': 'America/Los_Angeles',
  },
  'recurrence': [
    'RRULE:FREQ=DAILY;COUNT=2'
  ],
  'attendees': [
    {'email': 'lpage@example.com'},
    {'email': 'sbrin@example.com'},
  ],
  'reminders': {
    'useDefault': False,
    'overrides': [
      {'method': 'email', 'minutes': 24 * 60},
      {'method': 'popup', 'minutes': 10},
    ],
  },
}

event = service.events().insert(calendarId='primary', body=event).execute()
print 'Event created: %s' % (event.get('htmlLink'))

Ruby

event = Google::Apis::CalendarV3::Event.new(
  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: Google::Apis::CalendarV3::EventDateTime.new(
    date_time: '2015-05-28T09:00:00-07:00',
    time_zone: 'America/Los_Angeles'
  ),
  end: Google::Apis::CalendarV3::EventDateTime.new(
    date_time: '2015-05-28T17:00:00-07:00',
    time_zone: 'America/Los_Angeles'
  ),
  recurrence: [
    'RRULE:FREQ=DAILY;COUNT=2'
  ],
  attendees: [
    Google::Apis::CalendarV3::EventAttendee.new(
      email: 'lpage@example.com'
    ),
    Google::Apis::CalendarV3::EventAttendee.new(
      email: 'sbrin@example.com'
    )
  ],
  reminders: Google::Apis::CalendarV3::Event::Reminders.new(
    use_default: false,
    overrides: [
      Google::Apis::CalendarV3::EventReminder.new(
        reminder_method: 'email',
        minutes: 24 * 60
      ),
      Google::Apis::CalendarV3::EventReminder.new(
        reminder_method: 'popup',
        minutes: 10
      )
    ]
  )
)

result = client.insert_event('primary', event)
puts "Event created: #{result.html_link}"

予定にドライブの添付ファイルを追加する

Google ドライブを添付できます たとえば Google ドキュメントの会議メモ、 スプレッドシート、スライドのプレゼンテーション、 Google ドライブのファイルをカレンダーの予定に関連付けることができます。必要に応じて 予定の作成時に events.insert() 以降 events.patch() などの更新

Google ドライブのファイルを予定に添付するには、次の 2 つの操作を行います。

  1. からファイルの alternateLink の URL、titlemimeType を取得します。 Drive API Files リソース。通常は files.get() メソッドを使用します。
  2. リクエストの attachments フィールドを設定してイベントを作成または更新する body と supportsAttachments パラメータを true に設定します。

次のコード例は、既存のイベントを更新して 添付ファイル:

Java

public static void addAttachment(Calendar calendarService, Drive driveService, String calendarId,
    String eventId, String fileId) throws IOException {
  File file = driveService.files().get(fileId).execute();
  Event event = calendarService.events().get(calendarId, eventId).execute();

  List<EventAttachment> attachments = event.getAttachments();
  if (attachments == null) {
    attachments = new ArrayList<EventAttachment>();
  }
  attachments.add(new EventAttachment()
      .setFileUrl(file.getAlternateLink())
      .setMimeType(file.getMimeType())
      .setTitle(file.getTitle()));

  Event changes = new Event()
      .setAttachments(attachments);
  calendarService.events().patch(calendarId, eventId, changes)
      .setSupportsAttachments(true)
      .execute();
}

PHP

function addAttachment($calendarService, $driveService, $calendarId, $eventId, $fileId) {
  $file = $driveService->files->get($fileId);
  $event = $calendarService->events->get($calendarId, $eventId);
  $attachments = $event->attachments;

  $attachments[] = array(
    'fileUrl' => $file->alternateLink,
    'mimeType' => $file->mimeType,
    'title' => $file->title
  );
  $changes = new Google_Service_Calendar_Event(array(
    'attachments' => $attachments
  ));

  $calendarService->events->patch($calendarId, $eventId, $changes, array(
    'supportsAttachments' => TRUE
  ));
}

Python

def add_attachment(calendarService, driveService, calendarId, eventId, fileId):
    file = driveService.files().get(fileId=fileId).execute()
    event = calendarService.events().get(calendarId=calendarId,
                                         eventId=eventId).execute()

    attachments = event.get('attachments', [])
    attachments.append({
        'fileUrl': file['alternateLink'],
        'mimeType': file['mimeType'],
        'title': file['title']
    })

    changes = {
        'attachments': attachments
    }
    calendarService.events().patch(calendarId=calendarId, eventId=eventId,
                                   body=changes,
                                   supportsAttachments=True).execute()

予定にビデオ会議や電話会議を追加する

イベントは ハングアウトGoogle Meet の会議で ユーザーが電話またはビデオ通話でリモートで会うことができます。

conferenceData フィールドでは、 既存の会議の詳細の読み取り、コピー、クリアに使用するまた、 新しい会議の生成をリクエストするときに使用します。リソースの作成と 会議の詳細の変更、conferenceDataVersion リクエストの設定 パラメータを 1 に設定します。

現在サポートされている conferenceData は 3 種類あります。 conferenceData.conferenceSolution.key.type:

  1. 一般ユーザー向けハングアウト(eventHangout
  2. ユーザー向け Google Workspace 従来のハングアウト (非推奨、eventNamedHangout
  3. Google Meet(hangoutsMeet

カレンダーの特定のカレンダーでサポートされている会議の種類について、 conferenceProperties.allowedConferenceSolutionTypes を確認すると、 calendarscalendarList コレクション。また、 ユーザーが新たにすべてのユーザーの会議にハングアウトを作成 autoAddHangouts の設定を確認して、 settings コレクション。

type 以外にも、conferenceSolutionname と 次に示すように、会議ソリューションを表すために使用できる iconUri フィールド 下にあります。

JavaScript

const solution = event.conferenceData.conferenceSolution;

const content = document.getElementById("content");
const text = document.createTextNode("Join " + solution.name);
const icon = document.createElement("img");
icon.src = solution.iconUri;

content.appendChild(icon);
content.appendChild(text);

予定の新しい会議を作成するには、createRequest に以下の情報を指定します。 新しく生成された requestId(ランダムな string にすることもできます)。会議は 作成は非同期に行われますが、リクエストのステータスを ユーザーに状況を知らせることができます。

たとえば、既存のイベントの会議生成をリクエストするには、次のようにします。

JavaScript

const eventPatch = {
  conferenceData: {
    createRequest: {requestId: "7qxalsvy0e"}
  }
};

gapi.client.calendar.events.patch({
  calendarId: "primary",
  eventId: "7cbh8rpc10lrc0ckih9tafss99",
  resource: eventPatch,
  sendNotifications: true,
  conferenceDataVersion: 1
}).execute(function(event) {
  console.log("Conference created for event: %s", event.htmlLink);
});

この呼び出しに対する即時レスポンスには、データが入力されていない可能性があります。 conferenceData;ステータス コード pending で示されます。 ステータス 表示されます。会議情報が次の状態になると、ステータス コードが success に変わります。 データが入力されます。entryPoints フィールドには、どの動画と ユーザーがダイヤルインで電話の URI を使用できるようにします。

同じ名前で複数のカレンダーの予定をスケジュールする場合は、 編集したい場合は、1 つの予定から conferenceData 全体を 別のものです。

コピーは特定の状況で役立ちます。たとえば、Kubernetes Engine で 採用用のアプリケーションでは、候補者と、 面接官。面接官のアイデンティティを保護する必要がありますが、 すべての参加者が同じグループ通話に参加したことを確認するためです。