イントロOutlookのAPIへ - 私はv2のエンドポイントとサービスアカウントを使用する方法が表示されません。
v2のエンドポイントは、(limitation参照)現在のクライアント証明書をサポートしていません。 Azureポータルを使用してアプリケーションを登録/設定し、元のエンドポイントを使用してアプリケーションを認証する必要があります。アプリの登録の詳細については、hereを参照してください。そして、以下の図のようなメッセージを読むためにクライアント認証情報を使用するには、「すべてのメールボックスでメールを読む」必要があります。我々はまた、通知サブスクリプションを作成することができ、コードの助成金の流れでアプリを認証した場合、また
string clientId = "";
string clientsecret = "";
string tenant = "";
string resourceURL = "https://graph.microsoft.com";
string authority = "https://login.microsoftonline.com/" + tenant + "/oauth2/token";
string userMail = "";
var accessToken = new TokenHelper(authority).AcquireTokenAsync(clientId, clientsecret, resourceURL);
var graphserviceClient = new GraphServiceClient(
new DelegateAuthenticationProvider(
(requestMessage) =>
{
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", accessToken);
return Task.FromResult(0);
}));
var items = await graphserviceClient.Users[user].Messages.Request().OrderBy("receivedDateTime desc").GetAsync();
foreach (var item in items)
{
Console.WriteLine(item.Subject);
}
class TokenHelper
{
AuthenticationContext authContext;
public TokenHelper(string authUri)
{
authContext = new AuthenticationContext(authUri);
}
public string AcquireTokenAsync(string clientId, string secret,string resrouceURL)
{
var credential = new ClientCredential(clientId: clientId, clientSecret: secret);
var result = authContext.AcquireTokenAsync(resrouceURL, credential).Result;
return result.AccessToken;
}
}
:
そしてここでは、使用してメッセージを読み取るために、マイクロソフトグラフをクライアントの資格情報を使用してコードでありますメールボックスが新しいメッセージを受け取ったときのアプリ(webhoocks/subscription)
これは私が必要としていたものです。どうもありがとうございます! – vaindil