向MS Graph API进行批处理请求时出现未经授权的错误401

时间:2020-10-13 16:44:45

标签: microsoft-graph-api

我们有一个应用程序正在迁移到MS Graph API,以读取Email,进行一些处理,然后将它们移动到Different文件夹。我们能够连接到MS Graph并按顺序进行上述操作。但是,我们希望分批处理它们,以减少网络调用和延迟。

我们正在使用MSAL4J库开发Java应用,并引用链接:https://docs.microsoft.com/en-us/samples/azure-samples/graphapi-batching/batching-requests-to-msgraph/来创建批处理请求。

但是,当我们发送批处理请求时,我们遇到了以下错误(即使使用单个请求来获取用户详细信息)

Response {protocol = http / 1.1,code = 401,message = Unauthorized,url = https://graph.microsoft.com/v1.0/$batch}

添加的API /权限是具有管理员同意的Mail.ReadWrite和User.Read 您能否让我们知道批处理是否需要其他设置?

谢谢。

编辑1:

这是返回上述响应的代码

Request userRequest = new Request.Builder().url(graphClient.me().getRequestUrl()).build();
    MSBatchRequestStep userRequestStep = new MSBatchRequestStep("1", userRequest, null);
    
    
    // Create the batch request content with the steps created above
    List<MSBatchRequestStep> batchSteps = Arrays.asList(userRequestStep);
    MSBatchRequestContent batchRequestContent = new MSBatchRequestContent(batchSteps);

    ICoreAuthenticationProvider auth =
        (ICoreAuthenticationProvider)graphClient.getAuthenticationProvider();
    OkHttpClient client = HttpClients.createDefault(auth);

    // Send the batch request content to the /$batch endpoint
    String batchContent = batchRequestContent.getBatchRequestContent();
    Request batchRequest = new Request.Builder()
        .url("https://graph.microsoft.com/v1.0/$batch")
        .post(RequestBody.create(MediaType.parse("application/json"), batchContent))
        .build();

    Response batchResponse = client.newCall(batchRequest).execute();

0 个答案:

没有答案