在没有延迟的情况下循环响应时,Directory_ExpiredPageToken

时间:2018-04-10 14:01:03

标签: powershell microsoft-graph

我使用PowerShell访问Microsoft Graph,除了分页之外,它正像魅力一样工作。

我不时会遇到Directory_ExpiredPageToken错误。如果我在请求之间设置1秒的延迟,则错误大多消失。

$ReturnObject = @()
while ($Uri.Length -gt 0) {
    Add-TraceLine -Type DEBUG -Text "Calling '$($Uri)'"
    $Response = Invoke-RestMethod -Method GET -Uri $Uri -Headers $Headers
    $ReturnObject += $Response
    if ($Response.'@odata.nextlink') {
        $Uri = $Response.'@odata.nextlink'
        #Delay needed, otherwise Directory_ExpiredPageToken errors occured
        Start-Sleep -Milliseconds 1000
    }
    else {
        $Uri = $null
    }
}

有什么想法在这里发生?

延迟是一种解决方法,可以使用此模块运行工作流。但是我想因为性能原因而摆脱它。

编辑:

这是一个简化的JSON响应(值不仅是一个对象,而是一个数组)并且由于隐私/安全原因而稍有改变:

{
"@odata.context":  "https://graph.microsoft.com/v1.0/$metadata#users(department,displayName,ext2j5y6eqq_linkeduser,givenName,id,jobTitle,mail,mailNickname,surname,userPrincipalName)",
"@odata.nextLink":  "https://graph.microsoft.com/v1.0/users?$filter=userType+eq+%27Guest%27\u0026$select=department%2cdisplayName%2cext2j5y6eqq_linkeduser%2cgivenName%2cid%2cjobTitle%2cmail%2cmailNickname%2csurname%2cuserPrincipalName\u0026$skiptoken=RFNwdAkAAQAAAAAAAAAAFAAAADzX_JYCsThFmyry6_Ndz8kBAAAAAAAAAAAAAAAAAAAXMS4yLjg0MC4xMTM1NTYuMS40LjIzMzECAAAAAAABJruiMN_CtUmk63sXDRMMdg",
"value":  [
              {
                  "id":  "80f7fa19-2669-470d-86ac-ee4c052a5186",
                  "department":  null,
                  "displayName":  "XC Admin",
                  "givenName":  "XC",
                  "jobTitle":  null,
                  "mail":  null,
                  "mailNickname":  "xcadmin",
                  "surname":  "Admin",
                  "userPrincipalName":  "xcadmin@domain.onmicrosoft.com"
              }
          ]
}

编辑:

这是错误回复

+         ERROR   { throw $Line }
+                   ~~~~~~~~~~~
+ CategoryInfo          : OperationStopped: (11.04.2018-06:5...
}
}
}:String) [], RuntimeException
+ FullyQualifiedErrorId : 11.04.2018-06:50:13: <ERROR> - Get-User: {
"error": {
"code": "Directory_ExpiredPageToken",
"message": "The specified page token value has expired and can no longer be included in your request.",
"innerError": {
  "request-id": "13ecca81-2d8c-4d0f-a58e-4a9cdd72e100",
  "date": "2018-04-11T04:50:15"
}
}
}

0 个答案:

没有答案