본문 바로가기
개발자의 정보/Java & framework

Outlook 회의실 API 연동하기 (java example)

by pastory 2023. 2. 8.

Outlook은 회의실 예약을 포함하여 일정 관리를 위한 API를 제공합니다. Outlook API에 대해 자세히 알아보려면 다음 페이지를 방문하세요.



마이크로소프트 그래프 API - https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/resources/calendar

 

calendar resource type - Microsoft Graph v1.0

A calendar which is a container for events. It can be a calendar for a user, or the default calendar of a Microsoft 365 group.

learn.microsoft.com


여기에서 회의실 예약 방법을 포함하여 Microsoft Graph API를 사용하여 Outlook 일정과 상호 작용하는 방법에 대한 설명서 및 자습서를 찾을 수 있습니다.

또는 Microsoft EWS(Exchange Web Services) API를 사용하여 Outlook 일정과 상호 작용하고 회의실을 예약할 수도 있습니다. EWS에 대한 정보는 여기에서 찾을 수 있습니다.

Microsoft Exchange Web Services (EWS) API - https://docs.microsoft.com/en-us/exchange/client-developer/exchange-web-services/start-using-ews-javascript-api-to-work-with-email-calendar-and-contacts

회의실 예약 목록

다음은 Java에서 Microsoft Graph API를 사용하여 회의실 예약 목록을 검색할 수 있는 방법의 예입니다.

import java.io.IOException;
import java.util.List;

import com.microsoft.graph.authentication.IAuthenticationProvider;
import com.microsoft.graph.http.IHttpRequest;
import com.microsoft.graph.models.extensions.Event;
import com.microsoft.graph.requests.extensions.CalendarViewCollectionRequest;

public class GetMeetingRooms {

    public static void main(String[] args) throws IOException {
        IAuthenticationProvider authenticationProvider = // ... your authentication logic here

        CalendarViewCollectionRequest request = 
            new CalendarViewCollectionRequest("/me/calendar/calendarView", authenticationProvider);

        // Set the start and end time for the calendar view
        request.startDateTime("2022-01-01T00:00:00.0000000");
        request.endDateTime("2022-12-31T00:00:00.0000000");

        // Execute the request
        List<Event> events = request.get().getCurrentPage();

        // Filter the list to only include meeting room reservations
        events.stream()
            .filter(e -> e.isMeeting() && e.isMeetingRequest())
            .forEach(e -> System.out.println("Subject: " + e.subject + " Start: " + e.start.dateTime + " End: " + e.end.dateTime));
    }
}

이 코드에는 https://github.com/microsoftgraph/msgraph-sdk-java 링크에서 얻을 수 있는 Microsoft Graph Java 클라이언트 라이브러리가 필요합니다. 또한 여기서 자리 표시자 // ... your authentication logic을 애플리케이션을 인증하고 IAuthenticationProvider 인스턴스를 가져오는 데 필요한 코드로 바꿔야 합니다.

회의실 예약

다음은 Java에서 Microsoft Graph API를 사용하여 회의실 예약을 만드는 방법의 예입니다.

import java.io.IOException;
import java.util.Arrays;

import com.microsoft.graph.authentication.IAuthenticationProvider;
import com.microsoft.graph.models.extensions.Event;
import com.microsoft.graph.requests.extensions.EventsCollectionRequest;

public class RegisterMeetingRoom {

    public static void main(String[] args) throws IOException {
        IAuthenticationProvider authenticationProvider = // ... your authentication logic here

        Event event = new Event();
        event.subject = "Meeting Room Reservation";
        event.body = new ItemBody();
        event.body.content = "Reserving meeting room for team meeting";
        event.body.contentType = BodyType.HTML;
        event.start = new DateTimeTimeZone();
        event.start.dateTime = "2022-03-01T10:00:00.0000000";
        event.start.timeZone = "UTC";
        event.end = new DateTimeTimeZone();
        event.end.dateTime = "2022-03-01T12:00:00.0000000";
        event.end.timeZone = "UTC";
        event.location = new Location();
        event.location.displayName = "Meeting Room 1";
        event.attendees = Arrays.asList(new Attendee[] {
            new Attendee(),
            new Attendee()
        });
        event.attendees.get(0).emailAddress = new EmailAddress();
        event.attendees.get(0).emailAddress.address = "you@example.com";
        event.attendees.get(0).emailAddress.name = "Your Name";
        event.attendees.get(0).type = AttendeeType.REQUIRED;
        event.attendees.get(1).emailAddress = new EmailAddress();
        event.attendees.get(1).emailAddress.address = "meetingroom1@example.com";
        event.attendees.get(1).emailAddress.name = "Meeting Room 1";
        event.attendees.get(1).type = AttendeeType.RESOURCE;

        EventsCollectionRequest request = new EventsCollectionRequest("/me/events", authenticationProvider);

        // Execute the request to create the event
        Event createdEvent = request.post(event);

        System.out.println("Event created with ID: " + createdEvent.id);
    }
}

 

댓글