有什么方法可以使用IGraphServiceClient批量删除文件的所有权限吗?

问题描述 投票:1回答:1

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

使用的相关API:

microsoft-graph microsoft-graph-sdks microsoft-graph-files
1个回答
0
投票

您可以设置batch requests

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请求内容并获取内容

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
© www.soinside.com 2019 - 2024. All rights reserved.