OAuthMissingForThisService 此服务的身份验证需要 OAuth
OAuthMissingForThisService Authentication for this service requires OAuth
为什么我们无法再查询 office365 REST URL 来获取消息?
上周我可以通过转到 URL 阅读消息:https://outlook.office.com/api/v1.0/me/messages
现在我只能得到这个回复:
{"error":{"code":"OAuthMissingForThisService","message":"Authentication for this service requires OAuth: outlook.office.com."}}
谢谢
https://outlook.office.com/api/v1.0 doesn't support Basic auth as OAuth is the recommended auth mechanism, but you can continue to use https://outlook.office365.com/api/v1.0 如果您需要继续使用基本身份验证。
抱歉,我无法编辑我的问题以添加我向 Thomas 承诺的示例,所以这里是
(查看更多参考资料:https://msdn.microsoft.com/en-us/office/office365/api/mail-rest-operations)
`
//GET method for REST API
function ews_get($odata_command)
{
//$URL = 'https://outlook.office.com/api/v1.0/Me'; //doesn't work anymore
$URL = 'https://outlook.office365.com/api/v1.0/Me'; //Thanks Venkat :)
//concatenation of the command url
$URL .= $odata_command;
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page content
CURLOPT_FOLLOWLOCATION => true, // follow redirections
CURLOPT_AUTOREFERER => true, // set referer on redirections
CURLOPT_CONNECTTIMEOUT => 60, // timeout on connect
CURLOPT_TIMEOUT => 60, // timeout on response
CURLOPT_SSL_VERIFYPEER => false, // Disabled SSL Cert checks
CURLOPT_USERPWD => EWS_USERNAME . ':' . EWS_PASSWORD, //see constants
CURLOPT_HTTPAUTH => CURLAUTH_BASIC, //Basic authentication
);
$ch = curl_init($URL);
curl_setopt_array( $ch, $options );
$objResult = json_decode(curl_exec( $ch ));
curl_close( $ch );
return $objResult;
}
//Return a folder information for an Inbox subfolder named $displayName
function getInboxChildFolderByDisplayName($displayName)
{
//NOTE DEV: The $ sign is not correctly interpreted in a double quote string in php
//NOTE DEV: The ' in the url was replaced by %27
$results = ews_get('/Folders(\'Inbox\')/ChildFolders?$filter=DisplayName%20eq%20%27' . $displayName . '%27');
$arrFolderInfo = $results->value;
//return the first folder info
return $arrFolderInfo[0];
}
//Get messages from the folder id
function getMessagesFromFolderId($folderId = 'Inbox')
{
$objResult = ews_get("/Folders('" . $folderId . "')/Messages");
return $objResult->value;
}
/////////////
//Example
/////////////
$folder_id = getInboxChildFolderByDisplayName('MySubFolder')->Id;
$arrMessage = getMessagesFromFolderId($folder_id);
print_r($arrMessage);
//Have fun!
?>
`
为什么我们无法再查询 office365 REST URL 来获取消息?
上周我可以通过转到 URL 阅读消息:https://outlook.office.com/api/v1.0/me/messages
现在我只能得到这个回复:
{"error":{"code":"OAuthMissingForThisService","message":"Authentication for this service requires OAuth: outlook.office.com."}}
谢谢
https://outlook.office.com/api/v1.0 doesn't support Basic auth as OAuth is the recommended auth mechanism, but you can continue to use https://outlook.office365.com/api/v1.0 如果您需要继续使用基本身份验证。
抱歉,我无法编辑我的问题以添加我向 Thomas 承诺的示例,所以这里是 (查看更多参考资料:https://msdn.microsoft.com/en-us/office/office365/api/mail-rest-operations)
`
//GET method for REST API
function ews_get($odata_command)
{
//$URL = 'https://outlook.office.com/api/v1.0/Me'; //doesn't work anymore
$URL = 'https://outlook.office365.com/api/v1.0/Me'; //Thanks Venkat :)
//concatenation of the command url
$URL .= $odata_command;
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page content
CURLOPT_FOLLOWLOCATION => true, // follow redirections
CURLOPT_AUTOREFERER => true, // set referer on redirections
CURLOPT_CONNECTTIMEOUT => 60, // timeout on connect
CURLOPT_TIMEOUT => 60, // timeout on response
CURLOPT_SSL_VERIFYPEER => false, // Disabled SSL Cert checks
CURLOPT_USERPWD => EWS_USERNAME . ':' . EWS_PASSWORD, //see constants
CURLOPT_HTTPAUTH => CURLAUTH_BASIC, //Basic authentication
);
$ch = curl_init($URL);
curl_setopt_array( $ch, $options );
$objResult = json_decode(curl_exec( $ch ));
curl_close( $ch );
return $objResult;
}
//Return a folder information for an Inbox subfolder named $displayName
function getInboxChildFolderByDisplayName($displayName)
{
//NOTE DEV: The $ sign is not correctly interpreted in a double quote string in php
//NOTE DEV: The ' in the url was replaced by %27
$results = ews_get('/Folders(\'Inbox\')/ChildFolders?$filter=DisplayName%20eq%20%27' . $displayName . '%27');
$arrFolderInfo = $results->value;
//return the first folder info
return $arrFolderInfo[0];
}
//Get messages from the folder id
function getMessagesFromFolderId($folderId = 'Inbox')
{
$objResult = ews_get("/Folders('" . $folderId . "')/Messages");
return $objResult->value;
}
/////////////
//Example
/////////////
$folder_id = getInboxChildFolderByDisplayName('MySubFolder')->Id;
$arrMessage = getMessagesFromFolderId($folder_id);
print_r($arrMessage);
//Have fun!
?>
`