1

这是我到目前为止所拥有的,但我似乎无法找到 .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();
        }
4

1 回答 1

6

您可以在第一次调用$filter的参数中包含(或任何其他查询参数):requestOptionsbuildRequest()

// 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);
于 2019-01-11T17:12:00.687 回答