C# Microsoft Graph仅返回前100个用户
我有下面的代码,它根据过滤器返回所有用户。问题是它只返回100个用户,但我知道还有很多C# Microsoft Graph仅返回前100个用户,c#,microsoft-graph-api,microsoft-graph-sdks,C#,Microsoft Graph Api,Microsoft Graph Sdks,我有下面的代码,它根据过滤器返回所有用户。问题是它只返回100个用户,但我知道还有很多 private List<User> GetUsersFromGraph() { if (_graphAPIConnectionDetails == null) ReadParametersFromXML(); if (graphServiceClient == null) graphServiceClient = CreateGraphServiceClient();
private List<User> GetUsersFromGraph()
{
if (_graphAPIConnectionDetails == null) ReadParametersFromXML();
if (graphServiceClient == null) graphServiceClient = CreateGraphServiceClient();
var users = graphServiceClient
.Users
.Request()
.Filter(_graphAPIConnectionDetails.UserFilter)
.Select(_graphAPIConnectionDetails.UserAttributes)
.GetAsync()
.Result
.ToList<User>();
return users;
}
private List GetUsersFromGraph()
{
if(_graphAPIConnectionDetails==null)ReadParametersFromXML();
如果(graphServiceClient==null)graphServiceClient=CreateGraphServiceClient();
var users=graphServiceClient
.用户
.Request()
.Filter(_graphAPIConnectionDetails.UserFilter)
.Select(_graphAPIConnectionDetails.UserAttributes)
.GetAsync()
.结果
.ToList();
返回用户;
}
该方法仅返回100个用户对象。My Azure portal admin报告应该接近60000。Microsoft Graph中的大多数端点都返回页面中的数据,这包括
/users
为了检索其余结果,您需要浏览以下页面:
private async Task<List<User>> GetUsersFromGraph()
{
if (_graphAPIConnectionDetails == null) ReadParametersFromXML();
if (graphServiceClient == null) graphServiceClient = CreateGraphServiceClient();
// Create a bucket to hold the users
List<User> users = new List<User>();
// Get the first page
IGraphServiceUsersCollectionPage usersPage = await graphClient
.Users
.Request()
.Filter("filter string")
.Select("property string")
.GetAsync();
// Add the first page of results to the user list
users.AddRange(usersPage.CurrentPage);
// Fetch each page and add those results to the list
while (usersPage.NextPageRequest != null)
{
usersPage = await usersPage.NextPageRequest.GetAsync();
users.AddRange(usersPage.CurrentPage);
}
return users;
}
private异步任务GetUsersFromGraph()
{
if(_graphAPIConnectionDetails==null)ReadParametersFromXML();
如果(graphServiceClient==null)graphServiceClient=CreateGraphServiceClient();
//创建一个bucket来容纳用户
列表用户=新列表();
//获取第一页
IGraphServiceUsersCollectionPage usersPage=等待图形客户端
.用户
.Request()
.Filter(“过滤器字符串”)
.选择(“属性字符串”)
.GetAsync();
//将结果的第一页添加到用户列表
users.AddRange(usersPage.CurrentPage);
//获取每页并将这些结果添加到列表中
while(usersPage.NextPageRequest!=null)
{
usersPage=await usersPage.NextPageRequest.GetAsync();
users.AddRange(usersPage.CurrentPage);
}
返回用户;
}
这里有一个非常重要的注意事项,该方法是从Graph(或任何RESTAPI)检索数据的性能最低的方法。当你的应用程序下载所有这些数据时,它会在那里停留很长时间。这里正确的方法是获取每个页面,并在获取其他数据之前仅处理该页面 我同意。这是一天一次批量工作的一部分,所以我想我会没事的。但如果我想在用户操作的应用程序上使用此代码,我会接受你的观点。那么这将是一个问题。@Marc LaFleur,我正在使用这种方法,但正如你所说,这需要大量的时间。。。但我需要让用户以某种方式出现在列表中,因为当我去创建一个协作者时,我有一个azure广告用户下拉列表,我选择他们来创建具有该信息的用户。。。如何以最佳性能实现这一点?如果您有足够多的用户,这需要花费大量时间,那么他们可能不应该处于下拉列表中。您最好使用一个过滤用户列表的搜索框。