我使用garethp php-ews通过oauth2连接EWS。我正在接收访问令牌,但在将其传递给邮件函数(getMailItems、getMailbox、getFolder....etc)时,显示了带有"UnauthorizedException“的致命错误。尝试了很多方法,但仍然是一样的。
致命错误:未捕获C:\xampp\htdocs\exchange\vendor\garethp\php-ews\src\API\ExchangeWebServices.php:453堆栈跟踪中的garethp\ews\API\Exception\UnauthorizedException:#0 C:\xampp\htdocs\exchange\vendor\garethp\php-ews\src\API\ExchangeWebServices.php(368):garethp\ews\API\ExchangeWebServices->handleNonSuccessfulResponses(NULL,401) #1 C:\xampp\htdocs\exchange\vendor\garethp\php-ews\src\API\ExchangeWebServices.php(301):garethp\ews\API\ExchangeWebServices->processResponse(NULL) #2 C:\xampp\htdocs\exchange\vendor\garethp\php-ews\src\API.php(362):garethp\ews\API\ExchangeWebServices->__call('GetFolder',数组) #3 C:\xampp\htdocs\exchange\vendor\garethp\php-ews\src\API.php(378):garethp\ews\API->getFolder(数组) #4 C:\xampp\htdocs\exchange\vendor\garethp\php-ews\src\Mail\MailAPI.php(22):garethp\ews\API->getFolderByDistinguishedId('inbox') #5 C:\xampp\htdocs\exchange\vendor\garethp\php-ews\src\Mail\MailAPI.php(81):garethp\ews\Mail\Mail 453 >getFolderId() #6 C:\xampp\htdocs\exchange\testSync.php(50):garethp\ews\Mail\MailAPI in C:\xampp\htdocs\exchange\vendor\garethp\php-ews\src\API\ExchangeWebServices.php,第453行
下面是我传递的参数:
$tokenEndpoint = 'https://login.microsoftonline.com/common/oauth2/v2.0/token';
$authorizationEndpoint = 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize';
$clientId = '********';
$clientSecret = '********';
$redirectUri = 'http://localhost/testredirect.php';
$scope = 'https://outlook.office.com/Mail.Read';也尝试使用图形API:$scope = 'https://graph.microsoft.com/Mail.Read';
以下是我拥有的API权限:

发布于 2021-10-31 22:44:25
只有两个作用域用于EWS的委托访问,这是
仅适用于应用程序(客户端凭据流)
EWS不支持Microsoft Graph支持的更受约束的作用域,这些作用域是您引用的权限,从安全的角度来看,这是您通常选择Graph而不是EWS的原因。
https://stackoverflow.com/questions/69772631
复制相似问题