我使用 garethp php-ews 使用 oauth2 连接 EWS。我正在接收访问令牌,但在将其传递给邮件函数(getMailItems、getMailbox、getFolder....等)时,出现“UnauthorizedException”的致命错误。尝试了很多方法,但还是一样。
致命错误:未捕获 garethp\ews\API\Exception\UnauthorizedException 在 C:\xampp\htdocs\exchange\vendor\garethp\php-ews\src\API\ExchangeWebServices.php:453 堆栈跟踪:#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', Array) #3 C:\xampp\htdocs\exchange\vendor\garethp\php-ews\src\API.php (378): garethp\ews\API->getFolder(Array) #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\MailAPI->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';