Office365 API returns:观众声明值 'https://graph.microsoft.com' 的主机名部分无效

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

我似乎无法解决这个问题。我发现一些接近这个问题的问题说配置是问题,但是,我能够使用发送邮件功能。我刚刚开始学习 Office365 API,非常感谢您的帮助!

这是片段:

$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"

如果是配置(Azure AD),那我需要检查什么?如果这有帮助,我已将所有权限授予 Azure AD 中的 Microsoft Graph。

当您尝试访问 https://outlook.office.com.

时,您指定的访问令牌用于 https://graph.microsoft.com

尝试 https://graph.microsoft.com/v1.0/me/messages 而不是 https://outlook.office.com/api/v2.0/me/MailFolders/inbox/messages