如何使用Microsoft Graph API在Outlook上创build日历事件?

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

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:此链接标题为“创build事件”,似乎有请求和响应部分中列出的响应,使其特别令人困惑: 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:这个链接也被称为“创build事件”,但它有一个不同的POST URL:

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

很混乱。

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