我正在通过Node.js应用程序使用Microsoft的Graph API创建一个Outlook日历事件。遵循此文档/示例链接:https://docs.microsoft.com/en-us/previous-versions/office/office-365-api/api/version-2.0/calendar-rest-operations#CreateEvents
我的代码:
var options = {
method: 'POST',
url: 'https://graph.microsoft.com/v1.0/me/calendar/events',
headers: {
'Authorization': 'Bearer ' + access_token,
'Content-Type': 'application/json'
},
body: {
"subject": "Node.js outlook test",
"body": {
"contentType": "HTML",
"content": "Test event created from node.js"
},
"start": {
"dateTime": "2019-03-25T12:00:00",
"timeZone": "Pacific Standard Time"
},
"end": {
"dateTime": "2019-03-25T14:00:00",
"timeZone": "Pacific Standard Time"
},
"isAllDay": false,
"location": {
"displayName": null
},
"attendees": [{
"emailAddress": {
"address": "my-other-email@gmail.com",
"name": "Adele Vance"
},
"type": "required"
}]
},
json: true
};
request(options, function (err, response, body) {
if (err) throw new Error(err);
res.send(body);
});
该事件是在Outlook日历中创建的,但是没有与该事件关联的参与者。
创建事件后,我得到以下响应
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('my_hotmail_email%40hotmail.com')/calendar/events/$entity",
"@odata.etag": "W/\"69zWaBpmuEqq9NMFBSWV6QACU8X/gQ==\"",
"id": "AQMkADAwATYwMAItYzA3My1mNzUxLTAwAi0wMAoARgAAAwh1Hv4SptVMlm3BaW7y4g0HAOvc1mgaZrhKqvTTBQUAJZXpAAACAQ0AAADr3NZoGma4Sqr00wUFACWV6QACU7Qp1gAAAA==",
"createdDateTime": "2019-05-02T09:12:12.0349227Z",
"lastModifiedDateTime": "2019-05-02T09:12:12.0789547Z",
"changeKey": "69zWaBpmuEqq9NMFBSWV6QACU8X/gQ==",
"categories": [],
"originalStartTimeZone": "Pacific Standard Time",
"originalEndTimeZone": "Pacific Standard Time",
"iCalUId": "040000008200E00074C5B7101A82E0080000000077C77520C700D5010000000000000000100000001CB042E1D2C57341BA3D3799F9853B63",
"reminderMinutesBeforeStart": 15,
"isReminderOn": true,
"hasAttachments": false,
"subject": "Node.js outlook test",
"bodyPreview": "Test event created from node.js",
"importance": "normal",
"sensitivity": "normal",
"isAllDay": false,
"isCancelled": false,
"isOrganizer": true,
"responseRequested": true,
"seriesMasterId": null,
"showAs": "busy",
"type": "singleInstance",
"webLink": "https://outlook.live.com/owa/?itemid=AQMkADAwATYwMAItYzA3My1mNzUxLTAwAi0wMAoARgAAAwh1Hv4SptVMlm3BaW7y4g0HAOvc1mgaZrhKqvTTBQUAJZXpAAACAQ0AAADr3NZoGma4Sqr00wUFACWV6QACU7Qp1gAAAA%3D%3D&exvsurl=1&path=/calendar/item",
"onlineMeetingUrl": null,
"recurrence": null,
"responseStatus": {
"response": "organizer",
"time": "0001-01-01T00:00:00Z"
},
"body": {
"contentType": "html",
"content": "<html>\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n<meta content=\"text/html; charset=us-ascii\">\r\n</head>\r\n<body>\r\nDoes mid month work for you?\r\n</body>\r\n</html>\r\n"
},
"start": {
"dateTime": "2019-03-25T12:00:00.0000000",
"timeZone": "Pacific Standard Time"
},
"end": {
"dateTime": "2019-03-25T14:00:00.0000000",
"timeZone": "Pacific Standard Time"
},
"attendees": [
{
"type": "required",
"status": {
"response": "none",
"time": "0001-01-01T00:00:00Z"
},
"emailAddress": {
"name": "My Name",
"address": "my_hotmail_email@hotmail.com"
}
}
],
"organizer": {
"emailAddress": {
"name": "My Name",
"address": "my_hotmail_email@hotmail.com"
}
}
}
您可以在与会者数组中看到,它提供了我自己的hotmail / outlook帐户,但没有提供请求中包含的gmail帐户。
我的Gmail帐户也未收到任何日历邀请。任何想法可能出了什么问题吗?
答案 0 :(得分:1)
问题是您的Outlook / Hotmail帐户知道您的GMail地址。检查是否是这种情况的最简单方法是使用您的@gmail.com
地址但使用Outlook / Hotmail密码登录Outlook.com。如果您的Microsoft帐户将您的GMail地址列为有效别名,它将像对您输入的主要地址一样对您进行身份验证。
由于它将GMail地址视为别名,因此Outlook会自动将GMail别名换成您的“默认”地址(您的@outlook.com
地址)。
尝试使用新的GMail地址,它应该可以正常工作。