Microsoft Graph API 呼び出し時にAggregateException例外が発生する

Microsoft Graph API 呼び出し時にAggregateException例外が発生する現象と対処法を紹介します。

現象の確認

こちらの記事を一例とする、Microsoft GraphのAPIを呼び出すアプリケーションで、Microsoft GraphのAPIを呼び出す際に、例外が発生します。


次のエラーメッセージが表示されます。
エラーメッセージ
System.AggregateException
  HResult=0x80131500
  Message=One or more errors occurred. (Code: generalException
Message: An error occurred sending the request.

内部例外 1:
ServiceException: Code: generalException
Message: An error occurred sending the request.

内部例外 2:
MicrosoftIdentityWebChallengeUserException: IDW10502: An MsalUiRequiredException was thrown due to a challenge for the user.
  See https://aka.ms/ms-id-web/ca_incremental-consent. 

内部例外 3:
MsalUiRequiredException: AADSTS65001: The user or administrator has not consented to use the application
  with ID '(アプリケーションID)' named '(アプリケーション名)'. Send an interactive authorization request for this user and resource.
Trace ID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Correlation ID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Timestamp: (時刻)

原因

Microsoft Graph APIの呼び出し許可権限がない場合に上記のエラーが発生します。

対処法

Microsoft Graph APIの呼び出し許可を設定します.
設定手順はこちらの記事を参照してください。

著者
iPentecのメインプログラマー
C#, ASP.NET の開発がメイン、少し前まではDelphiを愛用
最終更新日: 2022-08-12
作成日: 2022-08-10
iPentec all rights reserverd.