dourao1896 2018-05-07 09:16
浏览 193
已采纳

Office365推送通知API错误:验证失败,因为响应正文

I am referring to o365 API documentation for adding push notification of calendar event. I am getting below error- Post>>

array:4 [▼
  "@odata.type" => "#Microsoft.OutlookServices.PushSubscription"
  "Resource" => "https://outlook.office.com/api/v2.0/me/events"
  "NotificationURL" => "https://mywebsite.com/notifications"
  "ChangeType" => "Created,Updated"
]
Response>>
"{"error":{"code":"ErrorInvalidParameter","message":"Notification URL 'https://mywebsite.com/notifications?validationtoken=ODFkNDllYWEtMmExYi00NDVjLWJmNzUtOTBhZjg3MDAyNjhh' verification failed because the response body '\tsuccess\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000' is unexpected."}} ◀"

My code is as-

$post_data = [          "@odata.type"=> "#Microsoft.OutlookServices.PushSubscription",
   "Resource"=>  "https://outlook.office.com/api/v2.0/me/events",
   "NotificationURL"=>  'https://mywebsite.com/notification',  
   "ChangeType"=>  "Created,Updated",
  // "expirationDateTime"=>  "2018-05-09T18:23:45.9356913Z",
  // "clientState"=> "testClientState"

  ];
   $curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_URL => "https://outlook.office.com/api/v2.0/me/subscriptions",
    //CURLOPT_URL => "https://graph.microsoft.com/beta/subscriptions",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => json_encode($post_data),
    CURLOPT_HTTPHEADER => array(
        // Set Here Your Requesred Headers
        'Authorization: Bearer '.TOKEN,
        'Content-Type: application/json',
        'X-CSRF-TOKEN: TOKEN-XXXXX'

    ),
));

How can I resolve the error?

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • duanqiang6501 2018-05-10 23:04
    关注

    Your notification endpoint must respond to a validation POST in a very specific way. Your response doesn't match that way, so the validation is failing.

    From https://developer.microsoft.com/en-us/graph/docs/concepts/webhooks:

    Microsoft Graph validates the notification URL in a subscription request before creating the subscription. The validation process occurs as follows:

    1. Microsoft Graph sends a POST request to the notification URL:

      POST https://{notificationUrl}?validationToken={TokenDefinedByMicrosoftGraph}
      ClientState: {Data sent in ClientState value in subscription request (if any)}
      
    2. The client must provide a response with the following characteristics within 10 seconds:

      • A 200 (OK) status code.
      • The content type must be text/plain.
      • The body must include the validation token provided by Microsoft Graph.

    The client should discard the validation token after providing it in the response.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么