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}
我失去了为什么它的行为会有所不同,以及为什么它在我们的内部环境中使用其证书,而不是在我们的环境上工作。我们尝试了自己的凭据,这再次适用于我们的凭据,但在他们的环境上产生了相同的错误。
# 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"
“一个任务已被取消”
发生由于多种原因,例如网络级限制或客户端和Microsoft Graph之间的连接问题。 要解决错误,检查以下:
MicrosoftGraph限制了防止过载的请求数量,因此,如果提出过多的请求,则可能会暂时阻止它们。您可以检查响应是否限制限制警告,并添加重试逻辑来处理此问题。 在某些情况下,取消任务错误可能是由于受影响环境中的超时导致的。如果在该环境中有更高的网络延迟,响应时间较慢或连接问题,请求可能会在它们完成之前超时。 检查完成前是否强行取消异步操作。如果服务具有取消任务逻辑或超时阈值,则可能会发生这种情况。
确保您的应用程序正确配置为在向Microsoft Graph API的请求时使用相同的代理设置。