期待される効果
予定を作成後、効果は以下のとおりです。統合フローの概要
本ドキュメントでは、社内アプリを作成し、予定が提供する API を使用して、予定の作成、変更、単一予定の詳細照会、削除のフローを実現する方法を示します。 前提条件:アプリの作成と設定のフローを完了してください。 ステップ 1:アプリ認証情報を取得し、クライアント ID と Client Secret を取得します。 ステップ 2:API 権限をリクエストし、予定関連 API の権限を申請します。 ステップ 3:アプリのアクセス認証情報を取得します。社内アプリの access_token を取得する。API 呼び出し時、access_token で呼び出し元の身元を認証します。 ステップ 4:サーバーサイドの予定関連 API を呼び出します。- サーバー API の 予定を作成 を呼び出し、予定を作成します。予定の
idを取得します。 - 予定の
idに基づき、サーバー API の 予定を変更 を呼び出し、予定情報を変更します。 - 予定の
idに基づき、サーバー API の 単一予定の詳細を照会 を呼び出し、予定の詳細情報を取得します。 - 予定の
idに基づき、サーバー API の 予定を削除 を呼び出し、作成した予定を削除します。
前提条件
アプリの作成と設定のフローを完了してください。ステップ 1:アプリ認証情報の取得
- 対象アプリを選択し、アプリ詳細ページに移動して、ベーシック情報 > 認証情報とベーシック情報 をクリックします。
- クライアント ID と Client Secret を取得します。
ステップ 2:API 権限の追加
開発設定 > 権限管理 をクリックし、権限検索ボックスにCalendar.Event.Write と Calendar.Event.Read をそれぞれ入力し、権限を申請します。
ステップ 3:アプリのアクセス認証情報 access_token の取得
サーバー API の差異の詳細は、旧版 API VS 新版 API を参照してください。以下の API はすべてサーバー API を使用しています。SDK ダウンロードの詳細は、サーバーサイド SDK ダウンロードを参照してください。
public void getAccessToken() throws Exception {
Config config = new Config();
config.protocol = "https";
config.regionId = "central";
com.aliyun.dingtalkoauth2_1_0.Client client = new com.aliyun.dingtalkoauth2_1_0.Client(config);
GetAccessTokenRequest accessTokenRequest = new GetAccessTokenRequest()
.setAppKey("ding*********hgn")
.setAppSecret("9G_O**********xamBkhgGIO");
GetAccessTokenResponse accessToken = client.getAccessToken(accessTokenRequest);
System.out.println(JSON.toJSONString(accessToken.getBody()));
}
ステップ 4:サーバーサイドの予定関連 API の呼び出し
-
サーバー API の 予定を作成 を呼び出し、予定を作成します。予定の
idを取得します。public void createCalendar() throws Exception { Config config = new Config(); config.protocol = "https"; config.regionId = "central"; com.aliyun.dingtalkcalendar_1_0.Client client = new com.aliyun.dingtalkcalendar_1_0.Client(config); CreateEventHeaders createEventHeaders = new CreateEventHeaders(); createEventHeaders.xAcsDingtalkAccessToken = "accessToken"; java.util.Map<String, String> extra = TeaConverter.buildMap( new TeaPair("noChatNotification", "false"), new TeaPair("noPushNotification","false") ); CreateEventRequest.CreateEventRequestOnlineMeetingInfo onlineMeetingInfo = new CreateEventRequest.CreateEventRequestOnlineMeetingInfo() .setType("dingtalk"); CreateEventRequest.CreateEventRequestReminders reminders0 = new CreateEventRequest.CreateEventRequestReminders() .setMethod("dingtalk") .setMinutes(15); CreateEventRequest.CreateEventRequestLocation location = new CreateEventRequest.CreateEventRequestLocation() .setDisplayName("********A座9F"); CreateEventRequest.CreateEventRequestAttendees attendees0 = new CreateEventRequest.CreateEventRequestAttendees() .setId("予定参加者unionId") .setIsOptional(false); CreateEventRequest.CreateEventRequestAttendees attendees1 = new CreateEventRequest.CreateEventRequestAttendees() .setId("予定参加者unionId") .setIsOptional(false); CreateEventRequest.CreateEventRequestAttendees attendees2 = new CreateEventRequest.CreateEventRequestAttendees() .setId("予定参加者unionId") .setIsOptional(false); CreateEventRequest.CreateEventRequestRecurrenceRange recurrenceRange = new CreateEventRequest.CreateEventRequestRecurrenceRange() .setType("numbered") .setNumberOfOccurrences(2); CreateEventRequest.CreateEventRequestRecurrencePattern recurrencePattern = new CreateEventRequest.CreateEventRequestRecurrencePattern() .setType("daily") .setInterval(1); CreateEventRequest.CreateEventRequestRecurrence recurrence = new CreateEventRequest.CreateEventRequestRecurrence() .setPattern(recurrencePattern) .setRange(recurrenceRange); CreateEventRequest.CreateEventRequestEnd end = new CreateEventRequest.CreateEventRequestEnd() .setDate("2022-09-03"); // .setDateTime("2021-09-20T10:15:30+08:00") // .setTimeZone("Asia/Shanghai"); CreateEventRequest.CreateEventRequestStart start = new CreateEventRequest.CreateEventRequestStart() .setDate("2022-09-02"); // .setDateTime("2021-09-20T10:15:30+08:00") // .setTimeZone("Asia/Shanghai"); CreateEventRequest createEventRequest = new CreateEventRequest() .setSummary("0902予定を作成") .setDescription("これは0902に作成された予定です") .setStart(start) .setEnd(end) .setIsAllDay(true) .setRecurrence(recurrence) .setAttendees(java.util.Arrays.asList( attendees0, attendees1, attendees2 )) .setLocation(location) .setReminders(java.util.Arrays.asList( reminders0 )) .setOnlineMeetingInfo(onlineMeetingInfo) .setExtra(extra); try { CreateEventResponse eventWithOptions = client.createEventWithOptions("予定組織者unionId", "primary", createEventRequest, createEventHeaders, new RuntimeOptions()); System.out.println(JSON.toJSONString(eventWithOptions.getBody())); } catch (TeaException err) { if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) { // err には code と message 属性が含まれ、開発者の問題特定に役立ちます System.out.println(err.code); System.out.println(err.message); } } catch (Exception _err) { TeaException err = new TeaException(_err.getMessage(), _err); if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) { // err には code と message 属性が含まれ、開発者の問題特定に役立ちます System.out.println(err.code); System.out.println(err.message); } } } -
予定の
idに基づき、サーバー API の 予定を変更 を呼び出し、予定情報を変更します。public void updateCalendar() throws Exception { Config config = new Config(); config.protocol = "https"; config.regionId = "central"; com.aliyun.dingtalkcalendar_1_0.Client client = new com.aliyun.dingtalkcalendar_1_0.Client(config); PatchEventHeaders patchEventHeaders = new PatchEventHeaders(); patchEventHeaders.xAcsDingtalkAccessToken = "accessToken"; PatchEventRequest.PatchEventRequestReminders reminders0 = new PatchEventRequest.PatchEventRequestReminders() .setMethod("dingtalk") .setMinutes(15); java.util.Map<String, String> extra = TeaConverter.buildMap( new TeaPair("noChatNotification", "false"), new TeaPair("noPushNotification","false") ); PatchEventRequest.PatchEventRequestLocation location = new PatchEventRequest.PatchEventRequestLocation() .setDisplayName("room 1-2-3"); PatchEventRequest.PatchEventRequestAttendees attendees0 = new PatchEventRequest.PatchEventRequestAttendees() .setId("予定参加者unionId") .setIsOptional(false); PatchEventRequest.PatchEventRequestRecurrenceRange recurrenceRange = new PatchEventRequest.PatchEventRequestRecurrenceRange() .setType("numbered") .setNumberOfOccurrences(1); PatchEventRequest.PatchEventRequestRecurrencePattern recurrencePattern = new PatchEventRequest.PatchEventRequestRecurrencePattern() .setType("daily") .setInterval(1); PatchEventRequest.PatchEventRequestRecurrence recurrence = new PatchEventRequest.PatchEventRequestRecurrence() .setPattern(recurrencePattern) .setRange(recurrenceRange); PatchEventRequest.PatchEventRequestEnd end = new PatchEventRequest.PatchEventRequestEnd() .setDate("2022-09-02"); PatchEventRequest.PatchEventRequestStart start = new PatchEventRequest.PatchEventRequestStart() .setDate("2022-09-02"); PatchEventRequest patchEventRequest = new PatchEventRequest() .setSummary("0902予定内容を変更") .setId("予定id") .setDescription("これは0902に変更された予定です") .setStart(start) .setEnd(end) .setIsAllDay(true) .setRecurrence(recurrence) .setAttendees(java.util.Arrays.asList( attendees0 )) .setLocation(location) .setExtra(extra) .setReminders(java.util.Arrays.asList( reminders0 )); try { PatchEventResponse patchEventResponse = client.patchEventWithOptions("予定組織者unionId", "primary", "予定id", patchEventRequest, patchEventHeaders, new RuntimeOptions()); System.out.println(JSON.toJSONString(patchEventResponse.getBody())); } catch (TeaException err) { if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) { // err には code と message 属性が含まれ、開発者の問題特定に役立ちます System.out.println(err.code); System.out.println(err.message); } } catch (Exception _err) { TeaException err = new TeaException(_err.getMessage(), _err); if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) { // err には code と message 属性が含まれ、開発者の問題特定に役立ちます System.out.println(err.code); System.out.println(err.message); } } } -
予定の
idに基づき、サーバー API の 単一予定の詳細を照会 を呼び出し、予定の詳細情報を取得します。public void calendarInfo() throws Exception { Config config = new Config(); config.protocol = "https"; config.regionId = "central"; com.aliyun.dingtalkcalendar_1_0.Client client = new com.aliyun.dingtalkcalendar_1_0.Client(config); GetEventHeaders getEventHeaders = new GetEventHeaders(); getEventHeaders.xAcsDingtalkAccessToken = "accessToken"; GetEventRequest getEventRequest = new GetEventRequest() .setMaxAttendees(100L); try { GetEventResponse eventWithOptions = client.getEventWithOptions("予定組織者unionId", "primary", "予定id", getEventRequest, getEventHeaders, new RuntimeOptions()); System.out.println(JSON.toJSONString(eventWithOptions.getBody())); } catch (TeaException err) { if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) { // err には code と message 属性が含まれ、開発者の問題特定に役立ちます System.out.println(err.code); System.out.println(err.message); } } catch (Exception _err) { TeaException err = new TeaException(_err.getMessage(), _err); if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) { // err には code と message 属性が含まれ、開発者の問題特定に役立ちます System.out.println(err.code); System.out.println(err.message); } } } -
予定の
idに基づき、サーバー API の 予定を削除 を呼び出し、作成した予定を削除します。public void deleteCalendar() throws Exception { Config config = new Config(); config.protocol = "https"; config.regionId = "central"; com.aliyun.dingtalkcalendar_1_0.Client client = new com.aliyun.dingtalkcalendar_1_0.Client(config); DeleteEventHeaders deleteEventHeaders = new DeleteEventHeaders(); deleteEventHeaders.xAcsDingtalkAccessToken = "accessToken"; try { client.deleteEventWithOptions("予定組織者unionId", "primary", "予定id", deleteEventHeaders, new RuntimeOptions()); } catch (TeaException err) { if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) { // err には code と message 属性が含まれ、開発者の問題特定に役立ちます System.out.println(err.code); System.out.println(err.message); } } catch (Exception _err) { TeaException err = new TeaException(_err.getMessage(), _err); if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) { // err には code と message 属性が含まれ、開発者の問題特定に役立ちます System.out.println(err.code); System.out.println(err.message); } } }
以下 2 種類の削除シナリオをサポートします。
- 主催者が予定を削除する場合(Path パラメータの userId に主催者の unionId を使用)、すべての参加者に予定キャンセル通知が送信され、同時に予定はすべての参加者のカレンダーから削除されます。
- 参加者が予定を削除する場合(Path パラメータの userId に参加者の unionId を使用)、予定は自身のカレンダーからのみ削除され、その他の予定参加者には影響しません。