Вы можете включить $filter
(или любой другой параметр запроса) в параметр requestOptions
первого вызова buildRequest()
:
// Include any filters in the initial request's `requestOptions`
List<Option> requestOptions = new ArrayList<Option>();
requestOptions.add(new QueryOption("$filter", "startsWith(displayName,'Foo')"));
IGroupCollectionRequest request = graphServiceClient.groups().buildRequest(requestOptions);
IGroupCollectionPage page = request.get();
// Process first page
IGroupCollectionRequestBuilder builder = page.getNextPage();
while (builder != null) {
request = builder.buildRequest();
page = request.get();
// Process each subsequent page
builder = page.getNextPage();
}
Альтернативный способ структурирования запросов (для того же результата), который, как мне кажется, немного легче читать:
IGroupCollectionPage page;
IGroupCollectionRequestBuilder builder;
// Build the initial request (including any filters)
List<Option> requestOptions = new ArrayList<Option>();
requestOptions.add(new QueryOption("$filter", "startsWith(displayName,'Foo')"));
IGroupCollectionRequest request = graphServiceClient.groups().buildRequest(requestOptions);
do {
// Make request
page = request.get();
// Process results
for(Group g: page.getCurrentPage()) {
System.out.println(g.displayName);
}
// Get and build request for next page
builder = page.getNextPage();
if (builder == null) {
request = null;
} else {
request = builder.buildRequest();
}
} while (request != null);