MS Graph API:找不到 OneDrive 资源找不到、资源、Graph、MS

2023-09-06 17:00:36 作者:\孤 馆

我正在构建一个 Windows 服务,该服务使用以下方法通过 Graph API 连接到 OneDrive for Business:https://graph.microsoft.io/en-us/docs/authorization/app_only

I'm building a Windows service that connects to OneDrive for Business via the Graph API using this method: https://graph.microsoft.io/en-us/docs/authorization/app_only

我已成功验证我的应用程序并拥有一个用于调用 Graph API 的令牌.我已将我的 Azure AD 应用程序权限授予 Windows Azure Active Directory 和 Microsoft Graph(已为两者选择了所有应用程序和委派权限).

I've successfully authenticated my application and have a token for making calls to Graph API. I have given my Azure AD application permissions to both Windows Azure Active Directory and Microsoft Graph (all application and delegated permissions have been selected for both).

我的目标是获取驻留在特定用户 OneDrive 中的文件夹的内容.我需要进行以下 Graph API 调用:

My goal is to get the contents of a folder that resides in a specific user's OneDrive. I need to make the following Graph API call:

//graph.microsoft.com/v1.0/users('user-guid')/drive/items/long-item-id-here/children

我可以使用 Microsoft Graph Explorer 成功执行此请求(使用我的 Office 365 凭据登录).当我尝试与应用程序进行相同的调用时(使用上面收到的身份验证令牌),我得到一个带有消息找不到资源"的itemNotFound"代码.(请求 ID:5e814dce-c4c2-4615-90e6-ea8ab90cbc49).但是,我可以查询根目录,并且folder.childCount"属性显示了根目录中正确的子节点数量:

I can execute this request successfully using Microsoft Graph Explorer (logged in with my Office 365 credentials). When I try to make the same call as an application (using the auth token received above), I get an "itemNotFound" code with the message "The resource could not be found." (request-id: 5e814dce-c4c2-4615-90e6-ea8ab90cbc49). However, I am able to query the root and the "folder.childCount" property shows the correct number of children in the root:

//graph.microsoft.com/v1.0/users('user-guid')/drive/root

我已将文件夹的共享设置为所有经过身份验证的用户",但仍然从 API 调用中收到找不到资源".

I've set the folder's sharing to "All Authenticated Users" and I still receive "The resource could not be found" from the API call.

关于我在这里缺少什么的任何想法?

Any ideas on what I'm missing here?

推荐答案

应用程序正在使用 仅应用授权,目前不支持通过 Microsoft Graph API 访问 OneDrive for Business.请使用 委托流程,供 Graph Explorer 使用.

The application is using App-only authorization which is currently not supported for accessing OneDrive for Business through Microsoft Graph API. Please use delegated flow, which is used by Graph Explorer.

 
精彩推荐
图片推荐