使用EWS

时间:2018-05-15 06:44:37

标签: php email oauth-2.0 exchangewebservices

我正在尝试使用oauth 2加载电子邮件列表。以下是我的代码:

    <?php

require_once "vendor/autoload.php";

use src\API\Type;
use garethp\ews\MailAPI as API;

$token='EwA......';    //access token

$api = API::withCallbackToken('outlook.office365.com', $token);
$mail = $api->getMailItems();
  foreach ($mail as $email) {
    $email = $api->getItem($email->getItemId());
    $email_id=$email->getItemId(); 
    $subject = $email->getSubject();
        $sender = $email->getSender()->getMailbox()->getEmailAddress();
        $body = (string) $email->getBody();

    echo $body;
} 

但得到的回应如下:

  

致命错误:未捕获的garethp \ ews \ API \ Exception \ UnauthorizedException   在   C:\的Inetpub \ wwwroot的\ bephpforTteam \新建\ php_ews \ PHP-EWS-主的\ src \ API \ ExchangeWebServices.php:438   堆栈跟踪:#0   C:\的Inetpub \ wwwroot的\ bephpforTteam \新建\ php_ews \ PHP-EWS-主\ SRC \ API \ ExchangeWebServices.php(356):   garethp \ EWS \ API \ ExchangeWebServices-&GT; handleNonSuccessfulResponses(NULL,   401)#1   C:\的Inetpub \ wwwroot的\ bephpforTteam \新建\ php_ews \ PHP-EWS-主\ SRC \ API \ ExchangeWebServices \ MiddlewareFactory.php(57):   garethp \ ews \ API \ ExchangeWebServices-&gt; processResponse(NULL)#2   C:\的Inetpub \ wwwroot的\ bephpforTteam \新建\ php_ews \ PHP-EWS-主\ SRC \ API \ ExchangeWebServices.php(497):   garethp \ EWS \ API \ ExchangeWebServices-&GT; garethp \ EWS \ API \ ExchangeWebServices {闭合}(对象(garethp \ EWS \ API \ MiddlewareRequest),   对象(关闭))#3   C:\的Inetpub \ wwwroot的\ bephpforTteam \新建\ php_ews \ PHP-EWS-主\ SRC \ API \ ExchangeWebServices \ MiddlewareFactory.php(66):   garethp \ ews \ API \ ExchangeWebServices-&gt; garethp \ ews \ API {closure}(对象(garethp \ ews \ API \ MiddlewareRequest))#4 C:\ inetpub \ wwwroot \ bephpforTt in C:\ inetpub \ wwwroot \ bephpforTteam \新建\ php_ews \ PHP-EWS-主的\ src \ API \ ExchangeWebServices.php   在第438行

0 个答案:

没有答案