1

作为用户操作的一部分,我们使用 MS Graph Java SDK 首先列出文件的所有权限,然后遍历权限列表以单独删除每个权限。这似乎有一些性能问题。我们想知道是否有任何方法可以使用 IGraphServiceClient 对调用进行批处理。

使用的相关API:

4

1 回答 1

0

您可以进行批量请求

1. 创建 MSBatch 请求步骤(示例如下)

Request requestGetMe = new Request.Builder().url("https://graph.microsoft.com/v1.0/me/").build();
List<String> arrayOfDependsOnIdsGetMe = null;
MSBatchRequestStep stepGetMe = new MSBatchRequestStep("1", requestGetMe, arrayOfDependsOnIdsGetMe);
Request requestGetMePlannerTasks = new Request.Builder().url("https://graph.microsoft.com/v1.0/me/planner/tasks").build();
List<String> arrayOfDependsOnIdsGetMePlannerTasks = Arrays.asList("1");
MSBatchRequestStep stepMePlannerTasks = new MSBatchRequestStep("2", requestGetMePlannerTasks, arrayOfDependsOnIdsGetMePlannerTasks);
String body = "{" + 
        "\"displayName\": \"My Notebook\"" + 
        "}";
RequestBody postBody = RequestBody.create(MediaType.parse("application/json"), body);
Request requestCreateNotebook = new Request
    .Builder()
        .addHeader("Content-Type", "application/json")
    .url("https://graph.microsoft.com/v1.0/me/onenote/notebooks")
    .post(postBody)
    .build();
MSBatchRequestStep stepCreateNotebook = new MSBatchRequestStep("3", requestCreateNotebook, Arrays.asList("2"));

2.创建MSBatch Request Content并获取内容

List<MSBatchRequestStep> steps = Arrays.asList(stepGetMe, stepMePlannerTasks, stepCreateNotebook);
MSBatchRequestContent requestContent = new MSBatchRequestContent(steps);
String content = requestContent.getBatchRequestContent();

3. 调用 $batch 端点

OkHttpClient client = HttpClients.createDefault(auth);
Request batchRequest = new Request
    .Builder()
    .url("https://graph.microsoft.com/v1.0/$batch")
    .post(RequestBody.create(MediaType.parse("application/json"), content))
    .build();
Response batchResponse = client.newCall(batchRequest).execute();

4. 创建 MSBatch 响应内容

MSBatchResponseContent responseContent = new MSBatchResponseContent(batchResponse);
Response responseGetMe = responseContent.getResponseById("1");
// Use the response of each request
于 2020-01-25T02:35:58.537 回答