序文
Microsoft Identity Platformを介してアクセストークンを取得した後、httpヘッダーにAuthorizationを追加し、Microsoft GraphAPIを呼び出してユーザーのOutlookカレンダーを操作できます。
実際、さまざまなリクエストの説明は、Outlookイベントの取得、カレンダーイベントの取得のためのMicrosoft Graph APIへの接続など、公式APIドキュメントでさらに詳しく説明されてい ます。
これは、主に以下の側面において、開発中の以下の注意点の要約です。
- ユーザーのOutlookカレンダーイベント(追加、削除、変更、およびチェック)を取得します
- ユーザーイベントの色設定を取得する
- 共有の会議や個人的なイベント
最初に効果を見てください
いくつかの一般的なコードを最初に置く
// 标准化返回值
class ResponseInfo {
constructor(status, data,msg) {
this.status = status;
this.data = data;
this.msg = msg;
}
}
// 用access Token注册 Graph client
function getAuthenticatedClient(accessToken) {
// Initialize Graph client
const client = graph.Client.init({
// Use the provided access token to authenticate
// requests
authProvider: (done) => {
done(null, accessToken);
}
});
return client;
}
1つは、ユーザーのOutlookカレンダーイベント(追加、削除、変更、およびチェック)を取得することです。
まず、Outlookカレンダーのイベントとカレンダーが異なることを忘れないでください。主な違いは、繰り返しのイベントにあります。たとえば、毎朝の会議です。カレンダービューから繰り返しイベント情報を取得できますが、通過した場合はイベントの場合、最初の繰り返しのみを取得できます。イベントデータ。
カレンダービューからイベントを取得するには、開始時間と終了時間の範囲を指定する必要があります。イベントからイベントを取得するには、時間範囲を指定する必要はありません。これは、イベントを介してイベントを取得する例です。
/**
* 获取用户events
*
* @param {*} accessToken 访问令牌
* @param {*} userPrincipalName 用户的微软账号(邮箱)
*/
getUserEvents : async function(accessToken,userPrincipalName){
try{
const client = getAuthenticatedClient(accessToken);
// timeZone:时区 默认是 Pacific Standard Time
let result = await client.api(`/users/${userPrincipalName}/events`)
.header('Prefer',`outlook.timezone="${timeZone}"`)
.get();
//console.log(result.value);
let response = new ResponseInfo(200,result.value,'');
return response;
}catch(errror) {
let response = new ResponseInfo(400,'',error);
return response;
}
},
/**
* 删除用户events
*
* @param {*} accessToken 访问令牌
* @param {*} userPrincipalName 用户的微软账号(邮箱)
* @param {*} eventsId event ID
* @returns
*/
delUserEvents : async function (accessToken, userPrincipalName, eventsId) {
try{
const client = getAuthenticatedClient(accessToken);
let result = await client.api(`/users/${userPrincipalName}/events/${eventsId}`)
.delete();
let response = new ResponseInfo(200,result,'');
return response;
}catch(errror) {
let response = new ResponseInfo(400,'',error);
return response;
}
},
/**
* 新增用户events
*
* @param {*} accessToken 访问令牌
* @param {*} userPrincipalName 用户的微软账号(邮箱)
* @param {*} newEvent event
* @returns
*/
setUserNewEvent : async function (accessToken,userPrincipalName,newEvent){
try{
const client = getAuthenticatedClient(accessToken);
//POST /users/{id | userPrincipalName}/events
let result = await client.api(`/users/${userPrincipalName}/events`)
.header('Prefer',`outlook.timezone="${timeZone}"`)
.post(newEvent);
let response = new ResponseInfo(200,result,'');
return response;
}catch(errror) {
let response = new ResponseInfo(400,'',error);
return response;
}
},
追加時にイベントに必要な基本フォーマットは以下のとおりです。
// timeZone:时区
const newEvent = {
subject: “件名”,
start: {
dateTime: “开始时间(UTC格式)”,
timeZone: timeZone
},
end: {
dateTime: “结束时间(UTC格式)”,
timeZone: timeZone
},
body: {
contentType: 'HTML',
content: “event内容”
},
location:{
displayName: “地点”
},
attendees:{},
};
次に、ユーザーイベントの色設定を取得します
なお、ユーザーが認証された場合、管理者でも自分のカテゴリ設定しか読み取れず、認証されたユーザー以外のメンバーのカテゴリ設定は読み取れませんが、ユーザー認証、つまりクライアントは通過していません。シークレット認証。その場合にのみ、すべてのユーザーのカテゴリ設定にアクセスできます。
また、ここで取得したカテゴリはフォームのみであり、公式のAPI返品例など、特定の色情報はありません。
コードを書いたときに色を選択しましたが、後で使用しませんでした。次の色に対応している必要があります。
カテゴリー | 色 |
プリセット0 | #FFFF14 |
プリセット1 | #FF8C00 |
プリセット2 | #FECB6F |
プリセット3 | #FFF100 |
プリセット4 | #5FBE7D |
プリセット5 | #33BAB1 |
プリセット6 | #A3B367 |
プリセット7 | #55ABE5 |
プリセット8 | #A895E2 |
プリセット9 | #E48BB5 |
プリセット10 | #B9C0CB |
プリセット11 | #4C596E |
プリセット12 | #ABABAB |
プリセット13 | #666666 |
プリセット14 | #474747 |
プリセット15 | #910A19 |
プリセット16 | #CE4B28 |
プリセット17 | #A47332 |
プリセット18 | #B0A923 |
プリセット19 | #026802 |
プリセット20 | #1C6367 |
プリセット21 | #5C6A22 |
プリセット22 | #254069 |
プリセット23 | #562685 |
プリセット24 | #80275D |
/**
* 用户事件类别取得
*
* @param {*} accessToken
* @param {*} userPrincipalName
*/
getUserMasterCategories : async function(accessToken,userPrincipalName) {
try{
const client = getAuthenticatedClient(accessToken);
let result =
await client.api(`/users/${userPrincipalName}/outlook/masterCategories`)
.get();
//console.log(result.value);
let response = new ResponseInfo(200,result.value,'');
return response;
}catch(errror) {
let response = new ResponseInfo(400,'',error);
return response;
}
},
3.共有会議と個人的なイベント
Outlookカレンダーで共有イベントを作成した後、他の人と共有すると会議になりますが、当分の間、イベントなのか会議なのかを区別するフラグが見つからないので、イベントの参加者を一時的に取得することによってのみ判断できますが、Outlookで作成されます。個人的なイベントの参加者には自分自身も含まれます。これには注意が必要です。他のユーザーが共有するOutlookイベントには、明確なフラグオーガナイザーがあるため、次のことができます。明確に判断されます。