尝试从 Graph 检索上次登录日期时间时的过滤器子句无效

Invalid filter clause when trying to retrieve last sign in date time from Graph

string date = DateTime.Today.AddDays(-30).ToString("yyyy-MM-ddTHH-mm-ssZ");

var users = await client.Users
                    .Request()
                    .Filter($"signInActivity/lastSignInDateTime le {date}")
                    .GetAsync();

这返回无效的过滤器子句错误,但似乎与此处详述的过滤器匹配:

https://docs.microsoft.com/en-us/graph/api/user-list?view=graph-rest-beta&tabs=http#example-5-list-the-last-sign-in-time-of-users-in-a-specific-time-range

我检查过邮件似乎也匹配。我错过了什么?

我在Microsoft Graph Explorer中尝试过这两个请求:

https://graph.microsoft.com/beta/users?$filter=signInActivity/lastSignInDateTime le 2021-07-21T00-00-00Z

其中 returns 一个 Invalid filter clause。此请求使用您的日期格式。

https://graph.microsoft.com/beta/users?$filter=signInActivity/lastSignInDateTime le 2021-07-21T00:00:00Z

which returns Calling principal does not have required MSGraph permissions AuditLog.Read.All 但这是正常的,因为我没有通过身份验证并使用了 Microsoft 的示例实例。我认为您的实例不会出现此错误。这个想法是过滤器在这里似乎是正确的。

问题似乎出在您的格式上,您应该尝试 ToString("yyyy-MM-ddTHH:mm:ssZ") 而不是 ToString("yyyy-MM-ddTHH-mm-ssZ")