您可以在第一次调用$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);