使用 msgraph-sdk-java 实现组 $filter 查询
Implementing a group $filter query using the msgraph-sdk-java
这是我目前所拥有的,但我似乎无法找到 .filter(s),是否以其他方式完成?
IGroupCollectionRequest request = graphServiceClient.groups().buildRequest();
IGroupCollectionPage page = request.get();
IGroupCollectionRequestBuilder builder = page.getNextPage();
while (builder != null) {
request = builder.buildRequest();
page = request.get();
builder = page.getNextPage();
}
您可以在第一次调用 buildRequest()
的 requestOptions
参数中包含 $filter
(或任何其他查询参数):
// 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);
这是我目前所拥有的,但我似乎无法找到 .filter(s),是否以其他方式完成?
IGroupCollectionRequest request = graphServiceClient.groups().buildRequest();
IGroupCollectionPage page = request.get();
IGroupCollectionRequestBuilder builder = page.getNextPage();
while (builder != null) {
request = builder.buildRequest();
page = request.get();
builder = page.getNextPage();
}
您可以在第一次调用 buildRequest()
的 requestOptions
参数中包含 $filter
(或任何其他查询参数):
// 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);