当我试图在PowerShell上使用Microsoft Graph API获取组的1000个线程时,504网关错误发生,代码停止。
但是如果我重新执行代码而不做任何更改,它运行得很好。为什么会发生这种情况,我应该如何避免这个问题?
$apiUrl53 = "https://graph.microsoft.com/beta/groups/" + $groups.id + "/threads?top=1000"
$Data = Invoke-WebRequest -Headers $global:__authHeader -Uri $apiUrl53 -Method Get
错误消息:
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
发布于 2019-07-19 00:04:01
有没有什么原因让你想进入前1000名呢?
例如,您可以“翻页”100个记录中的组,因此您不会在一个响应中返回如此巨大的有效负载。
有一个很棒的视频展示了如何使用skiptoken https://docs.microsoft.com/en-us/graph/paging?context=graph%2Fapi%2F1.0&view=graph-rest-1.0
例如,以下URL使用$top查询参数指定的页面大小5请求组织中的所有用户:
https://graph.microsoft.com/v1.0/users?$top=100
如果结果包含五个以上的用户,Microsoft Graph将返回一个@odata:nextLink属性,如下所示以及用户的第一页。
"@odata.nextLink": "https://graph.microsoft.com/v1.0/users?$top=100&$skiptoken=X%274453707 ... 6633B900000000000000000000%27"
您可以通过将@odata:nextLink属性的URL值发送到Microsoft Graph来检索下一页结果。
https://graph.microsoft.com/v1.0/users?$top=100&$skiptoken=X%274453707 ... 6633B900000000000000000000%27
Microsoft Graph将继续在每个响应的@odata:nextLink属性中返回对下一页数据的引用,直到读取了结果的所有页。
https://stackoverflow.com/questions/56846859
复制相似问题