簡體   English   中英

C# 圖 API TranslateExchangeIds().PostAsync() HTTP 方法不允許

[英]C# Graph API TranslateExchangeIds().PostAsync() HTTP Method not allowed

我正在使用 C# package 到 Microsoft Graph API。 我可以從 Graph API 中讀取消息。 現在我想翻譯如下所示的消息 ID: https://docs.microsoft.com/de-de/graph/api/user-translateexchangeids?view=graph-rest-1.0&tabs=csharp

var translatedIds = client.Users[firstMailboxElement.SourcePostbox]
  .TranslateExchangeIds(toBeTranslated, ExchangeIdFormat.RestImmutableEntryId, ExchangeIdFormat.RestId)
  .Request()
  .PostAsync()
  .Result;

當我這樣做時,我得到以下異常:

System.AggregateException
One or more errors occurred. 
(Code: Request_BadRequest Message: Specified HTTP method is not allowed for the request target. 
Inner error: AdditionalData: date: 2021-12-15T06:52:45 [...])

這似乎沒有意義,因為我無法更改 HTTP 方法。

任何想法如何解決這一問題?

var scopes = new[] { "https://graph.microsoft.com/.default" };
var tenantId = "your_tenant_name.onmicrosoft.com";
var clientId = "azure_ad_app_client_id";
var clientSecret = "client_secret";
var options = new TokenCredentialOptions
{
    AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
};
var clientSecretCredential = new ClientSecretCredential(
    tenantId, clientId, clientSecret, options);
var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
var inputIds = new List<String>()
{
    "asdf"
};
var sourceIdType = ExchangeIdFormat.RestId;
var targetIdType = ExchangeIdFormat.RestImmutableEntryId;
var res = graphClient.Users["user_id"].TranslateExchangeIds(inputIds, targetIdType, sourceIdType).Request().PostAsync();
var a = res.Result;

在此處輸入圖像描述

我發現,發生異常時, firstMailboxElement.SourcePostbox是 null。 所以調用去client.Users[null] ,所以請求 URL 是不完整的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM