2 回答

TA貢獻(xiàn)1864條經(jīng)驗(yàn) 獲得超6個(gè)贊
Microsoft Graph 中的大多數(shù)端點(diǎn)以頁面形式返回?cái)?shù)據(jù),這包括/users.
為了檢索您需要瀏覽頁面的其余結(jié)果:
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;
}
這里有一個(gè)非常重要的注意事項(xiàng),這種方法是從 Graph(或任何 REST API)中檢索數(shù)據(jù)的最不高效的方法。在下載所有這些數(shù)據(jù)時(shí),您的應(yīng)用程序?qū)⒃谀抢锿A艉荛L時(shí)間。此處正確的方法是獲取每個(gè)頁面并僅處理該頁面,然后再獲取其他數(shù)據(jù)。

TA貢獻(xiàn)1813條經(jīng)驗(yàn) 獲得超2個(gè)贊
我有一個(gè)類似的用例,我的查詢返回值 > 100。
final GroupCollectionPage userGroups = _appClient.users({id})
.memberOfAsGroup()
.buildRequest(requestOptions)
.select("displayName,id,mail")
.filter("startswith(displayName, 'c')")
.orderBy("displayName")
.get();
所以我可以輕松地遍歷結(jié)果集
// Output each Group details
for (Group usergroup : userGroups.getCurrentPage()) {
System.out.println(" User Group Name: " + usergroup.displayName);
System.out.println(" ID: " + usergroup.id);
System.out.println(" Email: " + usergroup.mail);
}
下面介紹如何獲取用戶組的下一頁
public static void getGroups() {
LinkedList<Option> requestOptions = new LinkedList<Option>();
requestOptions.add(new HeaderOption("ConsistencyLevel", "eventual"));
requestOptions.add(new QueryOption("$count", "true"));
GroupCollectionPage userGroups = _appClient.users({id})
.memberOfAsGroup()
.buildRequest(requestOptions)
.select("displayName,id,mail")
.filter("startswith(displayName, 'c')")
.orderBy("displayName")
.get();
List<Group> allGroupsList = new ArrayList<>();
do {
List<Group> currentPageGroup = userGroups.getCurrentPage();
allGroupsList.addAll(currentPageGroup);
GroupCollectionRequestBuilder nextPage = userGroups.getNextPage();
userGroups = nextPage == null ? null : nextPage.buildRequest().get();
} while (userGroups != null);
System.out.println("Total Group count is :" + allGroupsList.size());
for (Group usergroup : allGroupsList) {
System.out.println(" User Group Name: " + usergroup.displayName);
System.out.println(" ID: " + usergroup.id);
System.out.println(" Email: " + usergroup.mail);
}
}
- 2 回答
- 0 關(guān)注
- 223 瀏覽
添加回答
舉報(bào)