MicrosoftGraph API:取消任务

问题描述 投票:0回答:1
我们有一项服务,可以在Microsoft 365邮箱上监视电子邮件。该服务使用Client_credential身份验证(应用程序身份验证)。在我们的一个客户中,我们有一个例外,即在尝试和检索收件箱内容时取消了任务:

var inbox = await user.MailFolders.Inbox.Request().GetAsync(); A task was canceled System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Graph.HttpProvider.<SendRequestAsync>d__19.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Graph.HttpProvider.<SendAsync>d__18.MoveNext()
在我们的内部网络中,它可以正常工作,并且可以读取邮箱。因此,昨天我们尝试了另一种方法,因为我确定客户端代理或防火墙设置存在问题,因为似乎服务器的响应被阻止了。我们运行了一些卷发命令来获取令牌并尝试检索收件箱内容,这在收件箱内容的响应中成功了。
curl --location --request POST 'https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token' \ --header 'Content-Type: application/x-www-form-urlencoded' \ --data-urlencode 'client_id={clientid}' \ --data-urlencode 'scope=https://graph.microsoft.com/.default' \ --data-urlencode 'client_secret={clientsecret}' \ --data-urlencode 'grant_type=client_credentials' https://graph.microsoft.com/v1.0/users/{userid}/messages -x http://<proxy>:80 -H "Authorization: Bearer {token}

我失去了为什么它的行为会有所不同,以及为什么它在我们的内部环境中使用其证书,而不是在我们的环境上工作。我们尝试了自己的凭据,这再次适用于我们的凭据,但在他们的环境上产生了相同的错误。
	

azure microsoft-graph-api
1个回答
0
投票

# Define variables tenant_id="TenantID" client_id="ClientID" client_secret="Secret" user_id="UserID" proxy="http://<proxy>:xx" # Step 1: Get the OAuth token token_response=$(curl --location --request POST "https://login.microsoftonline.com/$tenant_id/oauth2/v2.0/token" \ --header 'Content-Type: application/x-www-form-urlencoded' \ --data-urlencode "client_id=$client_id" \ --data-urlencode "scope=https://graph.microsoft.com/.default" \ --data-urlencode "client_secret=$client_secret" \ --data-urlencode "grant_type=client_credentials") # Extract the access token from the response using jq access_token=$(echo "$token_response" | jq -r '.access_token') # Step 2: Use the token to fetch messages from the Graph API response=$(curl --location --request GET "https://graph.microsoft.com/v1.0/users/$user_id/messages" \ --proxy "$proxy" \ -H "Authorization: Bearer $access_token") # Print the response echo "$response"

错误

enter image description here“一个任务已被取消”

发生由于多种原因,例如网络级限制或客户端和Microsoft Graph之间的连接问题。 要解决错误,检查以下:

MicrosoftGraph限制了防止过载的请求数量,因此,如果提出过多的请求,则可能会暂时阻止它们。您可以检查响应是否限制限制警告,并添加重试逻辑来处理此问题。 在某些情况下,取消任务错误可能是由于受影响环境中的超时导致的。如果在该环境中有更高的网络延迟,响应时间较慢或连接问题,请求可能会在它们完成之前超时。 检查完成前是否强行取消异步操作。如果服务具有取消任务逻辑或超时阈值,则可能会发生这种情况。

确保您的应用程序正确配置为在向Microsoft Graph API的请求时使用相同的代理设置。
    Enhance登录您的申请书,以获取有关正在提出的请求和收到的响应的更多详细信息。
  • 如果仍然存在问题,请与Microsoft
  • 一起详细了解为什么它仅在客户端环境中失败,因为该问题在于客户环境而不是脚本。
  • 参考:
Subscription -Microsoft Graph API:ExtensionError:操作:创建;例外:[一个任务被取消。]意思是? - Menko的堆栈溢出。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.