Office365 API返回:受众声明值"https://graph.microsoft.com"的主机名组件无效
我似乎无法解决这个问题.我发现一些与此问题相关的问题,其中说配置是问题,但是,我可以使用发送邮件功能.我才刚刚开始学习Office365 API,将不胜感激!
I can't seem to work this out. I found some questions close to this issue that says configurations is the issue, however, I am able to use the send mail function. I am just starting to learn Office365 API and would greatly appreciate the help!
以下是代码段:
$curl = curl_init(
$headers = array(
'Authorization: Bearer ' . $_SESSION['access_token'],
'Content-Type: application/json;' .
'odata.metadata=minimal;' .
'odata.streaming=true'
);
curl_setopt_array(
$curl,
array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://outlook.office.com/api/v2.0/me/MailFolders/inbox/messages/',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_VERBOSE => 1,
CURLOPT_HEADER => 1
)
);
// The following curl options can be used in development to debug the code.
// Option to disable certificate verification. Do not use on production env.
// curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
// Option to set a proxy for curl to use.
// Useful if you want to review traffic with a tool like Fiddler.
// curl_setopt($curl, CURLOPT_PROXY, '127.0.0.1:8888');
// Enable error reporting on curl
//curl_setopt($curl, CURLOPT_FAILONERROR, true);
// Send the request & save response to a variable
$response = curl_exec($curl);
// Check for errors
if (curl_errno($curl)) {
print_r(curl_error($curl));
throw new \RuntimeException(curl_error($curl));
}
echo '<pre>';
print_r($response);
// Close request and clear some resources
curl_close($curl);
返回:
x-ms-diagnostics: 2000003;reason="The hostname component of the audience claim value 'https://graph.microsoft.com' is invalid";error_category="invalid_resource"
如果是配置(Azure AD),那么我需要检查什么?如果有帮助,我已授予Azure AD中Microsoft Graph的所有权限.
If it is the configurations (Azure AD), then what do I need to check? And if this helps, I've granted all permissions to Microsoft Graph in Azure AD.
您尝试访问https://outlook.office.com
时指定的访问令牌是https://graph.microsoft.com
的.
Your access token you've specified is for https://graph.microsoft.com
while you are trying to access https://outlook.office.com
.
尝试使用https://graph.microsoft.com/v1.0/me/messages
代替https://outlook.office.com/api/v2.0/me/MailFolders/inbox/messages
.