我正在使用 Outlook api 设置推送通知,服务器是用 nodejs 编写的。这是客户端为订阅发出的 post 请求
POST /api/v2.0/me/subscriptions HTTP/1.1
Host: outlook.office.com
Content-Type: application/json
client-request-id: f7d3812g-dfbz-4eb5-8edg-0f9a3ad716aq
User-Agent: node-outlook/2.0
return-client-request-id: true
X-Anchor-Mailbox: bill_gates@outlook.com
Authorization: Bearer "ACCESS_TOKEN"
Content-Type: application/json
{
"@odata.type":"#Microsoft.OutlookServices.PushSubscription",
"Resource": "https://outlook.office.com/api/v2.0/me/events",
"NotificationURL": "https://mywebsite.azurewebsites.net/push",
"ChangeType": "Created,Deleted,Updated"
}
然后,nodejs 服务器使用由 Outlook 通知服务生成的验证令牌进行响应
response.writeHead(200, { 'Content-Type': 'text/plain' });
response.write(validation_token);
response.end();
客户端(发送原始发布请求)然后收到以下响应
{
"@odata.context":"https://outlook.office.com/api/v2.0/$metadata#Me/Subscription/$entity",
"@odata.type": "#Microsoft.OutlookServices.PushSubscription",
"@odata.id": "https://outlook.office.com/api/v2.0/Users('00034001-ffef-f16e-0000-000000000000@74df9q7f-e9s6-40ad-b43w-aaaaaaaaaaaa')/Subscriptions('RERFNkJFNGUsNEE1My00RjFFLUExQkMtQkU1NkQ9OTdDOTlBXzAwMDM0MDAxLUZGRUYtZTE2RS0wMDAwLTAwMDAwMDAwMEAwMA==')",
"Id": "RERFNkJFNGUsNEE1My00RjFFLUExQkMtQkU1NkQ9OTdDOTlBXzAwMDM0MDAxLUZGRUYtZTE2RS0wMDAwLTAwMDAwMDAwMEAwMA==",
"Resource": "https://outlook.office.com/api/v2.0/me/messages",
"ChangeType": "Created, Updated, Deleted, Missed",
"NotificationURL": "https://mywebsite.azurewebsites.net/push",
"SubscriptionExpirationDateTime": "2017-03-30T09:35:37.6586596Z",
"ClientState": null
}
这正是 Outlook 文档状态应该发生的事情https://dev.outlook.com/restapi/concepts/webhooks
此过程验证 NotificationURL 以接收来自 Outlook 的推送通知。NotificationURL 端点在创建事件时收到来自 Outlook 的响应,但不是我想要的!
我应该期望收到这样的东西:
{
"value": [
{
"@odata.type": "#Microsoft.OutlookServices.Notification",
"Id": null,
"SubscriptionId": "Mjk3QNERDQQ==",
"SubscriptionExpirationDateTime": "2015-04-23T22:46:13.8805047Z",
"SequenceNumber": 1,
"ChangeType": "Created",
"Resource" : "https://outlook.office.com/api/v2.0/Users('ddfcd489-628b-7d04-b48b-20075df800e5@1717622f-1d94-c0d4-9d74-f907ad6677b4')/Events('AAMkADNkNmAA=')",
"ResourceData": {
"@odata.type": "#Microsoft.OutlookServices.Event",
"@odata.id": "https://outlook.office.com/api/v2.0/Users('ddfcd489-628b-7d04-b48b-20075df800e5@1717622f-1d94-c0d4-9d74-f907ad6677b4')/Events('AAMkADNkNmAA=')",
"Id": "AAMkADNkNmAA="
}
}
]
}
但相反,我收到了这样的东西
{
_readableState:
ReadableState {
objectMode: false,
highWaterMark: 16384,
buffer: BufferList { head: null, tail: null, length: 0 },
length: 0,
pipes: null,
pipesCount: 0,
flowing: null,
ended: false,
endEmitted: false,
reading: false,
sync: true,
needReadable: false,
emittedReadable: false,
readableListening: false,
resumeScheduled: false,
defaultEncoding: 'utf8',
ranOut: false,
awaitDrain: 0,
readingMore: true,
decoder: null,
encoding: null }, .......
这个响应正文又持续了 600 行。
我知道那里发生了很多事情,但是任何提示或帮助将不胜感激。