php - Outlook 通知 REST API 订阅所有日历

标签 php office365 office365api outlook-restapi

按照此处的说明进行操作:https://msdn.microsoft.com/en-us/office/office365/api/notify-rest-operations我得到:

订阅.php

    <?php
    $access_token=$_SESSION['access_token'];
    $user_email=$_SESSION['user_email'];
    $headers = array(
       "Authorization: Bearer ".$access_token ,
        "Accept: application/json",
        "X-AnchorMailbox: ".$user_email,
        "Content-Type: application/json"
      );
    $data = '{
       "@odata.type":"#Microsoft.OutlookServices.PushSubscription",
       "Resource": "https://outlook.office.com/api/v2.0/me/events",
       "NotificationURL": "https://mywebsite.com/listener.php",
       "ChangeType": "Created, Updated, Deleted",
       "ClientState": "secret"
    }';
    $curl = curl_init('https://outlook.office.com/api/v2.0/me/subscriptions');
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS,$data);
    $response = curl_exec($curl);

    $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
    if ($httpCode >= 400)echo "Request returned status: ".$httpCode;

    curl_close($curl);

  $json_vals = json_decode($response, true);
    echo '<pre>'.print_r($json_vals,true).'</pre>';

监听器.php

<?php
    if(isset($_REQUEST['validationtoken'])){
        echo $_REQUEST['validationtoken']; // needed only once when subscribing
    } else {
        $headers=getallheaders();
        if (isset($headers['ClientState']) && $headers['ClientState'] == "secret"){
            $body=json_decode(file_get_contents('php://input'));

            file_put_contents(__DIR__.'/listener.text', date("Y-m-d H:i:s").print_r($body,true),FILE_APPEND|LOCK_EX);

        }
    }

我把我的代码放在上面,因为我花了一段时间才弄清楚这一切,也许它对某人有帮助。但是,我仍然有一个问题,上面的代码只订阅了默认日历。如果我对其他日历进行更改,则不会发生任何事情。

如何使用 Outlook 通知 REST API 订阅所有日历而不仅仅是默认日历?

最佳答案

How do I use Outlook Notifications REST API to subscribe to all calendars not only to the default one?

要订阅其他日历的通知,您需要将“资源”更改为“me/calendars/{calendar_id}/events”。

{
  "@odata.type": "#Microsoft.OutlookServices.PushSubscription",
  "Resource": "me/calendars/{calendar_id}/events",
  "NotificationURL": "...",
  "ChangeType": "Created, Updated, Deleted"
}

similar question供您引用。

关于php - Outlook 通知 REST API 订阅所有日历,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36705523/

相关文章:

php - 不同年份和月份的日期范围

excel - 在组合框中永久添加值

azure - OpenID Connect 使用 Office 365 和 spring security 登录

c# - 在 UWP 中使用 Microsoft Graph API 为登录用户获取特定日期的 session 邀请和事件

android - 如何在 Azure Active Directory 中使 native 客户端应用程序成为单租户?

javascript - 如何使网站在使用和不使用 javascript 的情况下工作

javascript - 来自 PHP 文件的 HTML 按钮值之前有打印 "space"

php - 提供的值无效(无效的 IRI?)错误测试 api 平台端点

office365 - 无法将我的帐户用于 Microsoft 图形资源管理器

Azure AD token 颁发端点不返回 "scope"参数