java - 尝试使用 Microsoft Graph Java SDK 从共享 Outlook 日历获取忙/闲时段时出现错误 401

标签 java microsoft-graph-api microsoft-graph-sdks

我创建了两个新的 Outlook 帐户并与另一个共享了一个的 Outlook 日历。然后我尝试使用 Graph API Java SDK 获取共享日历空闲/忙碌时段:

 final String accessToken = resolveAccessToken(refreshToken);
    final IGraphServiceClient graphServiceClient = client.getClient(accessToken);

    ICalendarGetScheduleCollectionPage iCalendarGetScheduleCollectionPage = null;

    final DateTimeTimeZone startTime = new DateTimeTimeZone();
    startTime.dateTime = RFC339Utils.fromInstant(timeFrame.getStartAt());

    final DateTimeTimeZone endTime = new DateTimeTimeZone();
    endTime.dateTime = RFC339Utils.fromInstant(timeFrame.getEndAt());

    ICalendarGetScheduleCollectionPage iCalendarGetScheduleCollectionNextPage =
        graphServiceClient
            .me()
            .calendar()
            .getSchedule(emails, endTime, startTime, availabilityViewInterval)
            .buildRequest()
            .post();

对于这个请求,我收到了一个带有嵌套内部异常的空响应主体:

System.Net.WebException: The request failed with HTTP status 401: Unauthorized.\r\n   at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)\r\n   at System.Web.Services.Protocols.SoapHttpClientProtocol.EndInvoke(IAsyncResult asyncResult)\r\n   at Microsoft.Exchange.InfoWorker.Common.Availability.Proxy.Service.EndGetUserAvailability(IAsyncResult asyncResult)\r\n   at Microsoft.Exchange.InfoWorker.Common.Availability.FreeBusyApplication.EndProxyWebRequest(ProxyWebRequest proxyWebRequest, QueryList queryList, IService service, IAsyncResult asyncResult)\r\n   at Microsoft.Exchange.InfoWorker.Common.Availability.ProxyWebRequest.EndInvoke(IAsyncResult asyncResult)\r\n   at Microsoft.Exchange.InfoWorker.Common.Availability.AsyncWebRequest.EndInvokeWithErrorHandling()"

然后我尝试执行以下请求

POST https://graph.microsoft.com/v1.0/me/calendar/getSchedule

带有请求正文

{
  "schedules": [
    "joseph.baker.doodle@outlook.com"
  ],
  "startTime": {
    "dateTime": "2019-10-24T09:00:00",
    "timeZone": "Pacific Standard Time"
  },
  "endTime": {
    "dateTime": "2019-10-30T18:00:00",
    "timeZone": "Pacific Standard Time"
  },
  "availabilityViewInterval": 60
}

cURL 命令

curl 'https://graph.microsoft.com/v1.0/me/calendar/getSchedule' -H 'Connection: keep-alive' -H 'Accept: application/json, text/plain, */*' -H 'Origin: https://developer.microsoft.com' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36' -H 'SdkVersion: GraphExplorer/3.0' -H 'Authorization: Bearer {insert access token here}' -H 'Content-type: application/json' -H 'Sec-Fetch-Site: same-site' -H 'Sec-Fetch-Mode: cors' -H 'Referer: https://developer.microsoft.com/en-us/graph/graph-explorer' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: en-GB,en;q=0.9,en-US;q=0.8,sr;q=0.7,hr;q=0.6' --data-binary $'{\n  "schedules": [\n    "joseph.baker.doodle@outlook.com"\n  ],\n  "startTime": {\n    "dateTime": "2019-10-24T09:00:00",\n    "timeZone": "Pacific Standard Time"\n  },\n  "endTime": {\n    "dateTime": "2019-10-30T18:00:00",\n    "timeZone": "Pacific Standard Time"\n  },\n  "availabilityViewInterval": 60\n}' --compressed

我得到了这个回复

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(microsoft.graph.scheduleInformation)",
    "value": [
        {
            "scheduleId": "joseph.baker.doodle@outlook.com",
            "error": {
                "message": "Proxy web request failed. , inner exception: System.Net.WebException: The request failed with HTTP status 401: Unauthorized.\r\n   at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)\r\n   at System.Web.Services.Protocols.SoapHttpClientProtocol.EndInvoke(IAsyncResult asyncResult)\r\n   at Microsoft.Exchange.InfoWorker.Common.Availability.Proxy.Service.EndGetUserAvailability(IAsyncResult asyncResult)\r\n   at Microsoft.Exchange.InfoWorker.Common.Availability.FreeBusyApplication.EndProxyWebRequest(ProxyWebRequest proxyWebRequest, QueryList queryList, IService service, IAsyncResult asyncResult)\r\n   at Microsoft.Exchange.InfoWorker.Common.Availability.ProxyWebRequest.EndInvoke(IAsyncResult asyncResult)\r\n   at Microsoft.Exchange.InfoWorker.Common.Availability.AsyncWebRequest.EndInvokeWithErrorHandling()",
                "responseCode": "ErrorProxyRequestProcessingFailed"
            }
        }
    ]
}

这是 Outlook 方面的错误吗?如果有任何帮助,我将不胜感激。

最佳答案

Microsoft Graph API 不支持这种情况。我不认为日历共享可以通过 Microsoft Graph API 实现跨邮箱访问。

使用消费者帐户 (docs) 不允许委托(delegate)访问此 API。您正在使用/me,这意味着您正在尝试使用委托(delegate)访问。

关于java - 尝试使用 Microsoft Graph Java SDK 从共享 Outlook 日历获取忙/闲时段时出现错误 401,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58834212/

相关文章:

azure - [从 Azure AD Graph 迁移到 Microsoft Graph] : how to get the parameters to use the Microsoft Graph API

microsoft-graph-api - 根据 singleValueExtendedProperty 的特定值搜索事件

java - 使用 LocalDateTime 解析 DateTime 时异常无法从 TemporalAccessor 获取 LocalDateTime

java - 由于插入查询中的单引号导致的错误

java - JTabbedPane:仅绘制第一个选项卡,第二个选项卡始终为空(新手Q)

java - 在 HTTP Servlet 中使用连接池关闭连接的位置

c# - Azure AD 图 : Secure binary serialization is not supported on this platform

java - Microsoft Graph API 在订阅请求时给出 InternalServerError

azure 广告。授权流程是否需要从浏览器调用开始才能获取桌面应用程序的授权 token ?

c# - Microsoft Graph - GraphServiceClient 使用另一个帐户阅读电子邮件