이벤트 만들기

사용자가 최적의 하이킹 경로를 찾도록 도와주는 앱이 있다고 가정해 보겠습니다. 하이킹 계획을 캘린더 일정으로 추가하면 사용자가 자동으로 체계적으로 정리하는 데 많은 도움을 받을 수 있습니다. Google Calendar를 통해 계획을 공유하고 미리 상기하여 스트레스 없이 준비할 수 있습니다. 또한 Google 제품의 원활한 통합 덕분에 Google Now는 사용자에게 출발 시간을 알리고 Google 지도는 정시에 모임 장소로 사용자를 안내합니다.

이 도움말에서는 캘린더 일정을 만들어 사용자의 캘린더에 추가하는 방법을 설명합니다.

일정 추가

이벤트를 만들려면 최소한 다음 매개변수를 제공하는 events.insert() 메서드를 호출합니다.

  • calendarId는 캘린더 식별자이며 이벤트를 만들 캘린더의 이메일 주소이거나 로그인한 사용자의 기본 캘린더를 사용할 특수 키워드 'primary'일 수 있습니다. 사용하려는 캘린더의 이메일 주소를 모르는 경우 Google Calendar 웹 UI의 캘린더 설정('캘린더 주소' 섹션)에서 확인하거나 calendarList.list() 호출의 결과에서 찾을 수 있습니다.
  • event는 시작 및 종료와 같은 필요한 모든 세부정보를 포함하여 만들 이벤트입니다. 두 개의 필수 필드는 startend 횟수뿐입니다. 이벤트 필드의 전체 집합은 event 참조를 확인하세요.

이벤트를 만들려면 다음을 실행해야 합니다.

  • 사용자 캘린더에 대한 수정 액세스 권한을 갖도록 OAuth 범위를 https://www.googleapis.com/auth/calendar로 설정합니다.
  • 인증된 사용자에게 개발자가 제공한 calendarId를 사용하여 캘린더에 대한 쓰기 액세스 권한이 있는지 확인합니다 (예: calendarId에 대해 calendarList.get()를 호출하고 accessRole 확인).

이벤트 메타데이터 추가

캘린더 일정을 만들 때 일정 메타데이터를 추가할 수도 있습니다. 생성 중에 메타데이터를 추가하지 않을 경우 events.update()를 사용하여 많은 필드를 업데이트할 수 있습니다. 그러나 이벤트 ID와 같은 일부 필드는 events.insert() 작업 중에만 설정할 수 있습니다.

위치

위치 입력란에 주소를 추가하면 다음과 같은 기능을 사용할 수 있습니다.

"출발 시간 알림" 또는 길찾기와 함께 지도를 표시할 수 있습니다.

이벤트 ID

이벤트를 만들 때 자체 이벤트 ID를 생성할 수 있습니다.

동영상만 게재됩니다. 이렇게 하면 로컬 데이터베이스의 항목을 Google Calendar의 이벤트와 동기화된 상태로 유지할 수 있습니다. 또한 Calendar 백엔드에서 작업이 성공적으로 실행된 후 특정 시점에 실패하는 경우 중복 이벤트 생성이 방지됩니다. 이벤트 ID가 제공되지 않으면 서버에서 자동으로 생성됩니다. 자세한 내용은 이벤트 ID 참조를 확인하세요.

참석자

만든 일정은 다음 일정의 모든 기본 Google 캘린더에 나타납니다.

초대할 수 있습니다. 삽입 요청에서 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);
});

2,399필리핀

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

루비

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}"

일정에 Drive 첨부파일 추가하기

Docs의 회의록, Sheets의 예산, Slides의 프레젠테이션 또는 기타 관련 Google Drive 파일과 같은 Google Drive 파일을 캘린더 일정에 첨부할 수 있습니다. events.insert() 또는 이후 events.patch()를 사용하여 업데이트의 일부로 이벤트를 만들 때 연결을 추가할 수 있습니다.

일정에 Google Drive 파일을 첨부하는 작업은 다음 두 부분으로 이루어집니다.

  1. 일반적으로 files.get() 메서드를 사용하여 Drive API 파일 리소스에서 alternateLink URL, title, mimeType 파일을 가져옵니다.
  2. 요청 본문에 attachments 필드가 설정되어 있고 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();
}

2,399필리핀

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에는 conferenceData.conferenceSolution.key.type로 표시된 세 가지 유형이 있습니다.

  1. 일반 사용자를 위한 행아웃 (eventHangout)
  2. 사용자용 Google Workspace 기존 행아웃 (지원 중단됨, eventNamedHangout)
  3. Google Meet (hangoutsMeet)

calendarscalendarList 컬렉션에서 conferenceProperties.allowedConferenceSolutionTypes를 확인하여 특정 사용자의 캘린더에 지원되는 회의 유형을 확인할 수 있습니다. 또한 settings 컬렉션의 autoAddHangouts 설정을 확인하여 사용자가 새로 만든 모든 이벤트에 대해 행아웃을 만드는 것을 선호하는지 확인할 수 있습니다.

type 외에도 conferenceSolution는 아래와 같이 회의 솔루션을 나타내는 데 사용할 수 있는 nameiconUri 필드도 제공합니다.

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

새로 생성된 requestId(임의의 string일 수 있음)를 createRequest에 제공하여 이벤트의 새 회의를 만들 수 있습니다. 회의는 비동기식으로 생성되지만 언제든지 요청 상태를 확인하여 사용자에게 진행 상황을 알릴 수 있습니다.

예를 들어 기존 이벤트의 회의 생성을 요청하는 방법은 다음과 같습니다.

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가 포함되지 않을 수 있습니다. 이는 status 필드에 pending의 상태 코드로 표시됩니다. 회의 정보가 채워지면 상태 코드가 success로 변경됩니다. entryPoints 필드에는 사용자가 전화로 참여할 수 있는 동영상 및 전화 URI에 관한 정보가 포함됩니다.

회의 세부정보가 동일한 여러 캘린더 일정을 예약하려면 전체 conferenceData를 한 일정에서 다른 일정으로 복사하면 됩니다.

복사는 특정 상황에서 유용합니다. 예를 들어 지원자와 면접관에 대해 별도의 이벤트를 설정하는 채용 애플리케이션을 개발하면서 면접관의 신원을 보호하면서 모든 참가자가 동일한 다자간 통화에 참여하도록 하려고 한다고 가정해 보겠습니다.