我正在为新到达的电子邮件创建订阅,但 Microsoft Graph API 未创建订阅

问题描述 投票:0回答:1

订阅代码

var requestBody = new Subscription  { 
   ChangeType = "created,updated", 
   NotificationUrl =  "https://localhost:7230/Notification", 
   Resource = $"users/'{resultUsers.Value.FirstOrDefault().Id}'/mailFolders('inbox')/messages", 
   ExpirationDateTime = System.DateTimeOffset.UtcNow.AddMinutes(15), 
   ClientState = clientSecret, LatestSupportedTlsVersion = "v1_2",  
}; 
var result = await graphClient.Subscriptions.PostAsync(requestBody);

GraphClient 代码

  public GraphServiceClient MsGraphService()
  {
      //var scopes = "User.Read Mail.Read";
      //var scopesArray = scopes.Split(' ');
      var options = new TokenCredentialOptions
      {
          AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
      };
      var clientSecretCredential = new ClientSecretCredential(
          tenantId, clientId, clientSecret, options);
      GraphServiceClient graphServiceClient = new GraphServiceClient(clientSecretCredential, scopes);

      return graphServiceClient;
  }

例外我越来越

无法连接到远程服务器

我尝试更改 requestBody 中的资源,我认为这可能是问题所在,但仍然很困惑

c# azure asp.net-web-api microsoft-graph-api azure-ad-graph-api
1个回答
0
投票

错误

无法连接到远程服务器

意味着 Graph 无法连接到您的 Webhook 端点,这似乎是

NotificationUrl =“https://localhost:7230/Notification”,

云无法连接回 https://localhost,因此这需要是公共可访问端点,您可以在测试中使用 ngrok 之类的东西来执行此操作,请查看 https://learn.microsoft 的底部.com/en-us/samples/microsoftgraph/nodejs-webhooks-sample/microsoft-graph-webhooks-sample-for-nodejs/?source=recommendations 执行此操作。

© www.soinside.com 2019 - 2024. All rights reserved.