OUTLOOK REST API使用Node.js接受事件

我试图接受使用Rest API的事件,但我无法获得成功的响应,得到这样的答复:{“statusCode”:400,“body”:{“error”:{“code”:“ErrorInvalidRequest” ,“message”:“你的请求不能完成,因为你是会议组织者,所以你不能回应这个会议。”}。

代码试过,直到:

function getCalendarOfUser(email, token, startDate, endDate, iCalUId, callback) { console.log("retrieved Start Date: "+startDate+" ,End date: "+endDate); // startDate = '2016-03-10T10:27:00'; //endDate = '2016-05-10T11:27:00'; console.log("Email found in cookie: ", email); console.log("start date : ", startDate + " end date : " + endDate); var optionsForGettingcalendars = { // uri: 'https://outlook.office365.com/api/v2.0/me/calendarview?startDateTime=' + startDate + '&endDateTime=' + endDate, uri:'https://outlook.office.com/api/v2.0/me/events?$select=Subject,Organizer,Attendees,Start,End,iCalUId', port: 443, method: 'GET', headers: { 'Authorization': 'Bearer ' + token, 'Content-Length': 0 }, resolveWithFullResponse: true, simple: false }; rp(optionsForGettingcalendars) .then(function(response) { console.log("iCalUId to match : " + iCalUId); if (response.statusCode == 200 || response.statusCode == 201) { var events = response.body.value; var my_body = JSON.parse(response.body); my_body = my_body.value; console.log("EVENTS[] =========:: " + JSON.stringify(my_body) + '\n'); for (var i = 0; i < my_body.length; i++) { console.log("Matching My Calender Event: "+my_body[i].iCalUId + " to match with " + iCalUId); if (my_body[i].iCalUId == iCalUId) { console.log("MATCHED Event to ACCEPT/REJECT : " + JSON.stringify(my_body[i]) + '\n'); var result = { id: my_body[i].Id, message: "success" }; return callback(null, result); } } var error = { message: "error no match found fo calendar" }; return callback(error, null); } else if (response.statusCode == 401) { var error = { message: "refresh token" }; return callback(error, null); }else{ //var my_body = JSON.parse(response); console.log("Error Response: : " + JSON.stringify(response)); } }) .catch(function(err) { var error = { message: "error getting calendars" }; console.log("In Catch Block error" + JSON.stringify(err)); //return callback(error,null); }); } accept Event API: var requestBody = JSON.stringify({ "Comment": reasonForAccept, "SendResponse": "true" }); var optionsForDecliningEvent = { //uri: 'https://outlook.office365.com/api/v2.0/me/events/' + result.id + '/accept', uri: 'https://outlook.office.com/api/v2.0/me/events/' + result.id + '/accept', port: 443, method: 'POST', headers: { 'Authorization': 'Bearer ' + token, 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(requestBody) }, json: true, body: { "Comment": reasonForAccept, "SendResponse": "true" }, resolveWithFullResponse: true, simple: false }; var success=false; rp(optionsForDecliningEvent) .then(function(response) { console.log("response after accepting event : " + JSON.stringify(response)+" ,response.statusCode :"+response.statusCode); if (response.statusCode == 200 || response.statusCode == 201|| response.statusCode == 202) { logger.MessageQueueLog.log("info","index.cs:-Outlook: successfully accepted event"); mongoapi.updateDynamicDocuments("conference_details",where_query,{$pullAll:{'rejected_participants':[employee_id]},$addToSet:{'participant_ids': {$each:[employee_id]}}}, {multi:true},function(err,updateconfDetlArray){ if(err){ logger.MessageQueueLog.log("error","Outlook:Accept- MongoDB:- Unable to update Accepted Employee details into mongodb.Error is "+err); } else{ logger.MessageQueueLog.log("info","Outlook:Accept- MongoDB:-Accepted Updated Conference_details collection: "+JSON.stringify(updateconfDetlArray)); } }); success=true; var result = { type: "success" }; return callback(null,result); } else{ logger.MessageQueueLog.log("info","index.cs:-Outlook:Accept- Accepting Invitation Code,response.statusCode :"+response.statusCode); } }) .catch(function(err) { logger.MessageQueueLog.log("Error","index.cs:-Outlook:Accept- error in Catch Block: " + JSON.stringify(err)); if(success){ logger.MessageQueueLog.log("info","index.cs:-Outlook:Accept- successfully accepted event in catch block"); var result = { type: "success" }; //return callback(null,result); }else{ //success = false; logger.MessageQueueLog.log("info","index.cs:-Outlook:Accept- else of successfully accepted event in catch block"); var error = { message: "error getting calendars" }; //return callback(error,null); } }) 

任何帮助,将不胜感激。

提前致谢。

       

网上收集的解决方案 "OUTLOOK REST API使用Node.js接受事件"

作为组织者,您无法通过出席活动回应事件。 你有考勤状态值organizer

 "responseStatus": { "response": "organizer", "time": "0001-01-01T00:00:00Z" }, 

即使您在创build活动时将自己添加到与会者列表中,您将无法响应考勤,您将始终具有出席状态值none

 "attendees": [ { "status": { "response": "none", "time": "0001-01-01T00:00:00Z" }, "type": "required", "emailAddress": { "name": "Name Surname", "address": "name_surname@somewhere.com" } },