我正在使用outlook api设置推送通知,服务器是用nodejs编写的。这是客户为订阅做出的发布请求
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行。
我知道那里有很多事情,但任何提示或帮助将不胜感激。
答案 0 :(得分:0)
我刚刚找到了解决方案。当我从outlook通知中读取请求时,我必须将流转换为 on ,默认情况下将其设置为 null (请参阅上面的ReadableState JSON)。
这非常简单,只需 链接到请求正文,并使用回调。 可以在此处找到更多信息:https://www.sandersdenardi.com/readable-writable-transform-streams-node/
所以这就变成了
request.on('data', function(record) {
console.log('received: ' + record);
});