简体   繁体   English

Microsoft Graph API 尝试使用 $expand(microsoft.graph.itemattachment/item) 读取 ItemAttachment 属性时“访问被拒绝”

[英]Microsoft Graph API “Access is denied” while trying to read the ItemAttachment Properties with $expand(microsoft.graph.itemattachment/item)

I am trying to retrieve the properties of an ItemAttachment, which is of message type.我正在尝试检索消息类型的 ItemAttachment 的属性。 I have given all the required permissions and able to receive the ItemAttachment properties.我已授予所有必需的权限并且能够接收 ItemAttachment 属性。 But when I use $expand to get further properties of the ItemAttachment message.但是当我使用 $expand 来获取 ItemAttachment 消息的更多属性时。 I am getting Access Denied Error.我收到拒绝访问错误。

For what I have read it says that you need Mail.read permission which I have already given to my Azure AD application for Graph API and I am able to fetch all the messages but only when I try to use $expand to get the properties for the ItemAttachment which is of message type I am getting Access Denied.对于我所读到的内容,它说您需要Mail.read权限,我已经为我的 Azure AD 应用程序提供了 Graph API 并且我能够获取所有消息,但只有当我尝试使用 $expand 获取属性时消息类型的 ItemAttachment 我被拒绝访问。

I couldn't find any thing related to specific permissions that might be required for this to work on the microsoft doc ( https://docs.microsoft.com/en-us/graph/api/attachment-get?view=graph-rest-1.0&tabs=java ).我找不到与在 microsoft doc 上工作可能需要的特定权限相关的任何内容( https://docs.microsoft.com/en-us/graph/api/attachment-get?view=graph-休息-1.0&tabs=java )。

I also referred to a similar post ( How to retrieve contents of an itemAttachment via the Microsoft Graph API ) and do not find anything either.我还提到了一个类似的帖子( 如何通过 Microsoft Graph API 检索 itemAttachment 的内容)并且也没有找到任何东西。

Below are the details:以下是详细信息:

Java Code: Java 代码:

graphClient.me().messages(messageId).attachments(attachmentId)
                .buildRequest()
                .expand("microsoft.graph.itemattachment/item")
                .get();

This generates a REST call something like below:这会生成一个 REST 调用,如下所示:

GET https://graph.microsoft.com/v1.0/me/messages/A2zjArAAA=/attachments/5AlfysT-Cz27w=?$expand=microsoft.graph.itemattachment/item

But I am getting below "Access Denied" error.但是我遇到了“拒绝访问”错误。

403 : Forbidden
Cache-Control : private
Content-Length : 101
Content-Type : application/json; odata.metadata=minimal; odata.streaming=true; IEEE754Compatible=false; charset=utf-8
{
  "error": {
    "code": "ErrorAccessDenied",
    "message": "Access is denied. Check credentials and try again."
  }
}

I have the following permissions for my application Azure Active Directory Application:我的应用程序 Azure Active Directory 应用程序具有以下权限: 在此处输入图像描述

The microsoft graph API SdkVersion that I am using is: graph-java/v2.3.1.我正在使用的 microsoft graph API SdkVersion 是:graph-java/v2.3.1。

I am not sure if I am missing anything here.我不确定我是否在这里遗漏了什么。 Appreciate if anybody can please guide me towards a solution for this.感谢是否有人可以指导我解决这个问题。

As Shiva mentioned in comments, you use graphClient.me() in your code, but you assign Mail.Read permission of " Application " type.正如 Shiva 在评论中提到的,您在代码中使用graphClient.me() ,但您分配了“ Application ”类型的Mail.Read权限。 If assign " Application " type permission, it just requires client_id , scope , client_secret , grant_type to get access token.如果分配“应用程序”类型的权限,它只需要client_idscopeclient_secretgrant_type来获取访问令牌。 So the access token doesn't contain user info, ad do not know who is me , so the code graphClient.me() can't be recognized.因此访问令牌不包含用户信息,广告不知道me是谁,因此无法识别代码graphClient.me()

If you want to run the code( graphClient.me()... ) success, you need to add permission Mail.Read in " Delegated " type but not " Application " type (follow the steps in below screenshot and also do not forget do grant admin consent).如果你想运行代码( graphClient.me()... )成功,你需要添加权限Mail.Read在“ Delegated ”类型而不是“ Application ”类型(按照下面截图中的步骤,也不要忘记请授予管理员同意)。 在此处输入图像描述

As you are using application permissions it seams like you have a daemon application and the flow that you use for daemon applications will produce App token.当您使用应用程序权限时,它就像您有一个守护程序应用程序一样,您用于守护程序应用程序的流程将产生 App 令牌。 This doesn't recognise /me because there is no user here.这无法识别/me ,因为这里没有用户。 So try using /users/{userid}/messages .所以尝试使用/users/{userid}/messages

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM