Office365 API returns: the hostname component of the audience claim value 'https://graph.microsoft.com' is invalid

雨燕双飞 提交于 2019-12-11 00:59:10

问题


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!

Here is the snippet:

$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);

Returns:

x-ms-diagnostics: 2000003;reason="The hostname component of the audience claim value 'https://graph.microsoft.com' is invalid";error_category="invalid_resource"

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.


回答1:


Your access token you've specified is for https://graph.microsoft.com while you are trying to access https://outlook.office.com.

Try https://graph.microsoft.com/v1.0/me/messages instead of https://outlook.office.com/api/v2.0/me/MailFolders/inbox/messages.



来源:https://stackoverflow.com/questions/35026016/office365-api-returns-the-hostname-component-of-the-audience-claim-value-https

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!