gpt4 book ai didi

java - 使用 msgraph-sdk-java 实现组 $filter 查询

转载 作者:行者123 更新时间:2023-12-01 17:46:53 26 4
gpt4 key购买 nike

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

关于java - 使用 msgraph-sdk-java 实现组 $filter 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54149425/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com