Проблема заключается в вызове API FindMeetingTimes. Основная идея заключается в том, что он читает пользователей в арендаторе, читает их календари, находит время встречи для всех сторон, указанных в теле запроса, и создает событие в каждом из их календарей.На данный момент приложение может выполнить 3 из 4 требований (читать пользователей в арендаторе, читать их календари, создавать события в каждом календаре), однако у меня возникают проблемы с использованием времени встреч для тех же пользователей.Любое руководство или предложения могут помочь мне, потому что я все еще невероятно новичок как в nodejs, так и в Microsoft Graph.
Я попытался воспроизвести метод создания события, так как они оба являются пост-вызовами, но он ничего не возвращает в терминале.В настоящее время существует ошибка 500 внутреннего сервера, когда тот же URL вызывается в Graph Explorer, что может быть проблемой на этот раз.Но даже когда URL работает в графическом обозревателе, он все равно не возвращает ничего, как только он вызывается в коде.
graph.createEvent = function(token, users) {
var i;
var startTime;
var endTime;
var newEvent;
for (i = 0; i < users.length; i++) {
// The created event will be 30 minutes and take place tomorrow at the current time...
startTime = new Date();
startTime.setDate(startTime.getDate() + 1);
endTime = new Date(startTime.getTime() + 30 * 60000);
// Fields of the new calendar event...
newEvent = {
Subject: 'Company meeting',
Location: {
DisplayName: "Edison Ballroom"
},
Start: {
DateTime: startTime,
TimeZone: 'PST'
},
End: {
DateTime: endTime,
TimeZone: 'PST'
},
Body: {
Content: 'This meeting will review the benefits of this product.',
ContentType: 'Text'
}
};
// Adds the created event to the current user and other user's in the organization's calendar.
request.post({
url: 'https://graph.microsoft.com/v1.0/users/' + users[i].id + '/events',
headers: {
'content-type': 'application/json',
authorization: 'Bearer ' + token,
displayName: users[i].displayName
},
body: JSON.stringify(newEvent)
}, function(err, response, body) {
var parsedBody;
var displayName;
if (err) {
console.error('>>> Application error: ' + err);
} else {
parsedBody = JSON.parse(body);
displayName = response.request.headers.displayName;
if (parsedBody.error) {
if (parsedBody.error.code === 'RequestBroker-ParseUri') {
console.error(
'>>> Error creating an event for ' + displayName +
'. Most likely due to this user having a MSA instead of an Office 365 account.'
);
} else {
console.error(
'>>> Sorry could not create an event for ' + displayName + '. ' + parsedBody.error.message
);
}
} else {
console.log('>>> Successfully created an event on ' + displayName + "'s calendar.");
}
}
});
}
};
graph.findmeetingtimes = function(token, users) {
var i;
var startTime;
var endTime;
var MeetingTime;
for (i = 0; i < users.length; i++) {
startTime = new Date();
startTime.setDate(startTime.getDate() + 5);
endTime = new Date(startTime.getTime() + 30 * 60000);
//Fields to find meeting times, Attendees etc.
MeetingTime = {
attendees: [{
type: 'required',
emailAddress: {
address: 'jidoe@44321.onmicrosoft.com',
name: 'Jim Doe'
}
},
{
type: 'required',
emailAddress: {
address: 'jdoe@44321.onmicrosoft.com',
name: 'Jane Doe'
}
},
{
type: 'required',
emailAddress: {
address: 'bthomas@44321.onmicrosoft.com',
name: 'Bob Thomas'
}
}
],
locationconstraint: {
isRequired: true,
suggestLocation: true,
locations: [{
resolveAvailability: false,
displayName: "Edison Ballroom"
}]
},
timeconstraint: {
activityDomain: 'work',
timeslots: [{
start: {
dateTime: startTime,
timeZone: "PST"
},
end: {
dateTime: endTime,
timeZone: "PST"
}
}]
},
meetingDuration: "PT1H",
MaxCandidates: 99,
IsOrganizerOptional: false,
returnSuggestionReasons: true,
minimumAttendeePercentage: 100
}
};
// Looks up avaliable meeting times for all attendees and returns meeting time suggestions.
request.post({
url: 'https://graph.microsoft.com/v1.0/me/' + users[i].id + '/findMeetingTimes',
headers: {
'content-type': 'application/json',
authorization: 'Bearer ' + token,
Prefer: outlook.timezone,
},
body: JSON.stringify(MeetingTime)
}, function(err, response, body) {
var parsedBody;
var meetingTimeSuggestionsResult;
if (err) {
console.error(' Application error: ' + err);
} else {
parsedBody = JSON.parse(body);
meetingTimeSuggestionsResult = response.request.headers.meetingTimeSuggestionsResult;
if (parsedBody.error) {
if (parsedBody.error.code === 'RequestBroker-ParseUri') {
console.error(' Error ')
} else {
console.error('Sorry there was an error in your request' + parsedBody.error);
}
} else {
console.log(meetingTimeSuggestionsResult);
}
}
});
}
Фактическая цель состоит в том, чтобы вернуть какой-то ответ в терминале, если это бэкэнд API.Тем не менее, нет результата, который возвращается после вызова метода в файле app.js.