Microsoft Graph 获取所有用户仅返回 100 个用户

Meh*_*lal 4 c# microsoft-graph-api

Microsoft graph 100返回用户,我如何从Microsoft graph获取所有用户

 var users = graphServiceClient
   .Users
   .Request()
   .GetAsync()
   .GetAwaiter()
   .GetResult();
Run Code Online (Sandbox Code Playgroud)

我怎样才能获得所有用户?

Dmi*_*nko 6

MS Graph 使用具有默认记录页面大小的分页输出。您刚刚阅读了默认用户的第一页。100100

您可能想要这样的东西(查询通常很慢,这就是我创建它们的原因async):

var users = await graphServiceClient
  .Users
  .Request()
  .Top(999)  // <- Custom page of 999 records (if you want to set it)
  .GetAsync()
  .ConfigureAwait(false);

while (true) {
  //TODO: relevant code here (process users)

  // If the page is the last one
  if (users.NextPageRequest is null)
    break;

  // Read the next page
  users = await users
    .NextPageRequest
    .GetAsync()
    .ConfigureAwait(false);
} 
Run Code Online (Sandbox Code Playgroud)