Office365 push notification API error: verification failed because the response body

Office365 push notification API error: verification failed because the response body

我指的是 o365 API 添加日历事件推送通知的文档。我得到低于错误 - 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."}} ◀"

我的代码是-

$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'

    ),
));

如何解决错误?

提前致谢。

您的通知端点必须以非常具体的方式响应验证 POST。您的回复与此不符,因此验证失败。

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

Microsoft Graph 在创建订阅之前验证订阅请求中的通知 URL。验证过程如下:

  1. Microsoft Graph 向通知发送 POST 请求 URL:

    POST https://{notificationUrl}?validationToken={TokenDefinedByMicrosoftGraph}
    ClientState: {Data sent in ClientState value in subscription request (if any)}
    
  2. 客户端必须在 10 秒内提供具有以下特征的响应:

    • 200(正常)状态代码。
    • 内容类型必须是text/plain。
    • 正文必须包含 Microsoft Graph 提供的验证令牌。

客户端应在响应中提供验证令牌后将其丢弃。