【问题标题】:Office 365 'Create Event' Rest API is giving errorOffice 365“创建事件”Rest API 出现错误
【发布时间】:2015-07-09 14:10:45
【问题描述】:

我是 stackoverflow 以及使用 node.js 进行 Office 365 开发的新用户。

我使用本教程成功获取用户(我自己的 office 365 帐户)邮件、日历事件 (https://dev.outlook.com/RestGettingStarted/Tutorial/node)

但是当我试图在我的日历中创建一个事件时,它给了我以下错误 "{"error":{"code":"ErrorAccessDenied","message":"访问被拒绝。检查凭据并重试。"}}"

请给我同样的建议。

下面是我从[https://msdn.microsoft.com/office/office365/APi/calendar-rest-operations#CreateEvents]这里复制的创建事件的代码

    function createEvent(response, request) {
var cookieName = 'node-tutorial-token';
   var cookie = request.headers.cookie;
//    if (cookie && cookie.indexOf(cookieName) !== -1) {
        console.log("Cookie: ", cookie);
        // Found our token, extract it from the cookie value
        var start = cookie.indexOf(cookieName) + cookieName.length + 1;
        var end = cookie.indexOf(';', start);
        end = end === -1 ? cookie.length : end;
        var token = cookie.substring(start, end);
        console.log("Token found in cookie: " + token);

var event = new outlook.Microsoft.OutlookServices.Event();
event.subject = 'Your Subject';
event.start = new Date("October 30, 2014 11:13:00").toISOString();
event.end = new Date("October 30, 2014 12:13:00").toISOString();

// Body
event.body = new outlook.Microsoft.OutlookServices.ItemBody();
event.body.content = 'Body Content';
event.body.contentType = outlook.Microsoft.OutlookServices.BodyType.Text;

// Location
event.location = new outlook.Microsoft.OutlookServices.Location();
event.location.displayName = 'Location';

// Attendee
var attendee1 = new outlook.Microsoft.OutlookServices.Attendee();
var emailAddress1 = new outlook.Microsoft.OutlookServices.EmailAddress();
emailAddress1.name = "abc";
emailAddress1.address = "abc@abcdt.onmicrosoft.com";

attendee1.emailAddress = emailAddress1;

event.attendees.push(attendee1);
 var outlookClient = new outlook.Microsoft.OutlookServices.Client('https://outlook.office365.com/api/v1.0', 
       authHelper.getAccessTokenFn(token));

outlookClient.me.calendar.events.addEvent(event)
    .then(function (response) {
    console.log(response._Id);
}, function (error) {
        console.log(error);

});

}

【问题讨论】:

  • 欢迎来到 SO。请给你看代码。
  • 您是否为您的应用申请了 calendar.readwrite 权限?
  • @UweAllner 我已经用代码更新了我的问题。
  • @VenkatAyyadevara-MSFT 我试图从 Outlook 授予我自己的委托权限,但它说“你不能在委托权限用户中添加你自己”。
  • 您无需在 Outlook 中将自己添加为代理人。看我的回答。

标签: node.js office365


【解决方案1】:

确保您的应用已请求 calendar.readwrite 权限,并且您需要此权限来创建新事件。在您遵循的示例中,您的应用仅注册了 Calendar.Read 权限(见下文)。

您应该转至https://dev.outlook.com/AppRegistration 注册具有创建新事件所需的 Calendar.ReadWrite 权限的应用程序。

【讨论】:

  • 它正在工作!非常感谢@Venkat。我还有一个关于创建事件的问题,因为使用上面的代码我可以在我自己的 office 365 帐户中创建事件,但是我想为我组织中其他用户的 office 帐户创建事件,请你建议我需要哪些步骤采取。
  • 目前尚不支持使用 REST API 访问其他用户的日历,但我们正在努力添加此支持。我没有为此分享的时间表。
  • 好的@Venkat Ayyadevara - MSFT,除 REST API 之外,其他的 REST API 是他们在我阅读本文时在同一组织内的其他用户的 Office 365 帐户中创建事件的任何方式 [blogs.msdn.com/b/exchangedev /archive/2015/01/21/…不知何故符合我的要求,你能建议我吗?
  • 您可以使用 Exchange Web 服务。见msdn.microsoft.com/EN-US/library/office/…
猜你喜欢
  • 1970-01-01
  • 2015-04-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-26
  • 1970-01-01
  • 2018-03-30
  • 1970-01-01
相关资源
最近更新 更多