3

我有一个与 Office365 集成的应用程序,我正在尝试使用 Microsoft Graph API 在 Outlook 日历上创建一个日历事件。这是我到目前为止所拥有的:

        request.post({
            url:'https://graph.microsoft.com/v1.0/me/events',
            form: {
                "Id": null,
                "Subject": "Discuss the Calendar REST API",
                "Body": {
                    "ContentType": "Text",
                    "Content": "This is some content."
                },
                "Start": {
                    "DateTime": "2016-01-24T18:00:00",
                    "TimeZone": "Pacific Standard Time"
                },
                "End": {
                    "DateTime": "2016-01-25T19:00:00",
                    "TimeZone": "Pacific Standard Time"
                },
                "ShowAs": "Free",
                "IsReminderOn":false
            },
            headers: {
                "Authorization": "Bearer " + access_token,
                "Content-Type": "application/json"
            }
        }, function(err, httpResponse, body) {
            if (err) {
                console.log('addMicrosoftAccessToken() ERROR = ' + err);
                callback(err, false);
            } else {
                console.log('httpResponse = ' + JSON.stringify(httpResponse));
                callback(null, true);
            }
        })

问题是该事件未保存在用户 Outlook 日历上。另外,我在日志中没有收到错误。我怀疑我没有在请求中发送正确的表单数据。有任何想法吗?

更新:这是httpResponse我在日志中得到的:

{
    "statusCode": 500,
    "body": "{\r\n  \"error\": {\r\n    \"code\": \"UnknownError\",\r\n    \"message\": \"\",\r\n    \"innerError\": {\r\n      \"request-id\": \"8ebe2efc-649c-4d8d-bee1-be2457cc3a45\",\r\n      \"date\": \"2016-01-25T19:05:27\"\r\n    }\r\n  }\r\n}",
    "headers": {
        "cache-control": "private",
        "transfer-encoding": "chunked",
        "content-type": "application/json",
        "server": "Microsoft-IIS/8.5",
        "request-id": "8ebe2efc-649c-4d8d-bee1-be2457cc3a45",
        "client-request-id": "8ebe2efc-649c-4d8d-bee1-be2457cc3a45",
        "x-ms-ags-diagnostic": "{\"ServerInfo\":{\"DataCenter\":\"East US\",\"Slice\":\"SliceB\",\"ScaleUnit\":\"000\",\"Host\":\"AGSFE_IN_4\",\"ADSiteName\":\"EST\"}}",
        "outboundduration": "707.5019",
        "duration": "713.2419",
        "x-powered-by": "ASP.NET",
        "date": "Mon, 25 Jan 2016 19:05:27 GMT",
        "connection": "close"
    },
    "request": {
        "uri": {
            "protocol": "https:",
            "slashes": true,
            "auth": null,
            "host": "graph.microsoft.com",
            "port": 443,
            "hostname": "graph.microsoft.com",
            "hash": null,
            "search": null,
            "query": null,
            "pathname": "/v1.0/me/events",
            "path": "/v1.0/me/events",
            "href": "https://graph.microsoft.com/v1.0/me/events"
        },
        "method": "POST",
        "headers": {
            "Authorization": "Bearer blah blah",
            "Content-Type": "application/x-www-form-urlencoded",
            "Accept": "application/json",
            "content-length": 643
        }
    }
}

更新 2:此链接标题为“创建事件”,并且似乎在请求和响应部分中都列出了响应,使其特别混乱: http: //graph.microsoft.io/docs/api-reference/v1。 0/api/event_post_instances 另外,在上面列出的链接中

POST https://graph.microsoft.com/v1.0/me/events/<id>/instances

什么是<id>?它没有告诉我 id 应该是什么?

更新 3:此链接也标题为“创建事件”,但它具有不同的 POST URL:

http://graph.microsoft.io/docs/api-reference/v1.0/api/user_post_events

非常混乱。

4

1 回答 1

1

您的我/事件请求失败的原因是您使用 Azure Active Directory (AAD) 授权流来访问您的个人 Microsoft 帐户 (Live Id) 日历。AAD 允许创建映射到 Microsoft 帐户的用户,以便在请求 AAD 令牌时使用您的 Microsoft 帐户凭据登录。这样,您的凭据可用于访问企业(工作或学校)和消费者(个人)服务。虽然凭据是共享的,但有 2 个不同的用户帐户。访问 OneDrive for Business 或 SharePoint 等业务服务时,您需要在工作或学校组织的上下文中使用 AAD 用户帐户登录。访问 Hotmail 或 OneDrive 等消费者服务时,您需要使用 Microsoft 帐户 (Live Id) 登录。您的请求正在尝试访问您组织环境中的 Outlook 帐户,该帐户不存在,因为您的电子邮件地址已由与您的 Microsoft 帐户关联的个人 Outlook 帐户提供服务。请使用融合授权流程(http://graph.microsoft.io/en-us/docs/authorization/converged_auth)使用您的个人 Microsoft 帐户登录,您将能够访问您的个人电子邮件和日历。或者,您可以继续使用 AAD 授权流来访问未映射到 Microsoft 帐户的 AAD 用户的工作或学校日历。

于 2016-02-19T18:05:23.687 回答