Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Azure 无法从Microsoft Graph API获取邮件_Azure_Azure Ad Graph Api - Fatal编程技术网

Azure 无法从Microsoft Graph API获取邮件

Azure 无法从Microsoft Graph API获取邮件,azure,azure-ad-graph-api,Azure,Azure Ad Graph Api,我正在尝试使用Graph API从我的outlook帐户获取邮件。我正在使用已配置应用程序的组织outlook帐户 我成功地从apihttps://login.microsoftonline.com/common/oauth2/v2.0/token但在查询api时,我得到以下错误 { "error": { "code": "BadRequest", "message": "Current authenticated context is not valid

我正在尝试使用Graph API从我的outlook帐户获取邮件。我正在使用已配置应用程序的组织outlook帐户

我成功地从api
https://login.microsoftonline.com/common/oauth2/v2.0/token
但在查询api时,我得到以下错误

{
    "error": {
        "code": "BadRequest",
        "message": "Current authenticated context is not valid for this request. This occurs when a request is made to an endpoint that requires user sign-in. For example, /me requires a signed-in user.  Acquire a token on behalf of a user to make requests to these endpoints.  Use the OAuth 2.0 authorization code flow for mobile and native apps and the OAuth 2.0 implicit flow for single-page web apps.",
        "innerError": {
            "request-id": "807ce785-38b6-4fbb-b670-6419768b08c3",
            "date": "2019-06-21T11:59:26"
        }
    }
}
我使用的API是
https://graph.microsoft.com/v1.0/me/messages
我使用的标题是:

X-AnchorMailbox:{{my_email}}
Accept:application/json
Authorization:Bearer {{token}}

我使用的应用程序是用于查询api的postman。

正如错误消息所说,您获得的令牌实际上没有在用户上下文中签名。您可能使用OAuth2客户端凭据流来获取令牌,而对于调用/me方法,您需要使用隐式授权流,它将用户重定向到login.microsoftonline.com以登录,然后使用获得的(通过委派权限)令牌来调用图

所以你基本上有两个选择:

  • 使用委派权限、隐式授权流(用户以交互方式登录)和
  • 使用应用程序权限、客户端凭据授予流(无需用户登录)和{userPrincipalName}/messages