Microsoft公式のチュートリアルに沿ってアプリ作成し、サインインまではできアクセストークンの取得はできました。
しかし、途中のメールの取得や予定表の取得のリクエストを投げると、以下のエラーが発生してデータを取得することができません。
▼エラー
"FetchError: request to https://graph.microsoft.com/v1.0/me/mailfolders/inbox/messages?$top=10&$select=subject,from,receivedDateTime,isRead&$orderby=receivedDateTime DESC failed, reason: unable to verify the first certificate"
Graphエクスプローラーで同じリクエストを投げてデータが取得できることは確認できているので、AzureADやアプリ側の設定だと思うのですが、原因が特定できません。
原因と解決方法をお分かりの方はいらっしゃらないでしょうか。
●参考:Outlook のメール、予定表、および連絡先を取得する Node.js アプリの記述
https://docs.microsoft.com/ja-jp/outlook/rest/node-tutorial
ソースはチュートリアルのままです。
// Initialize Graph client
const client = graph.Client.init({
authProvider: (done) => {
done(null, accessToken);
}
});
try {
// Get the 10 newest messages from inbox
const result = await client
.api('/me/mailfolders/inbox/messages')
.top(10)
.select('subject,from,receivedDateTime,isRead')
.orderby('receivedDateTime DESC')
.get();
parms.messages = result.value;
res.render('mail', parms);
} catch (err) {
parms.message = 'Error retrieving messages';
parms.error = { status: `${err.code}: ${err.message}` };
parms.debug = JSON.stringify(err.body, null, 2);
res.render('error', parms);
}
よろしくお願いします。
追記
別のチュートリアルアプリでは同じリクエストでデータを取得することができます。
ただ、何がどう違うのかがよくわかりません。また使いたいのは質問している方なので、解決したいです。
●参考:ユーザーをサインインして、JavaScript シングルページ アプリケーション (SPA) から Microsoft Graph API を呼び出す
https://docs.microsoft.com/ja-jp/azure/active-directory/develop/tutorial-v2-javascript-spa