简体   繁体   English

无法使用Microsoft Graph以全局管理员身份查询用户的OneDrive业务文件

[英]Cannot Query Users' OneDrive For Business Files As The Global Administrator using Microsoft Graph

Logged in and authenticated as the Global Admin in O365 Enterprise subscription, I can query all users using Microsoft Graph. 登录并通过O365 Enterprise订阅中的Global Admin进行身份验证,我可以使用Microsoft Graph查询所有用户。 I can also query individual users with the User.Id . 我还可以使用User.Id查询单个用户。

But when I try to query the OneDrive files ( DriveItem ) for any user then I get an empty response and resource not found error. 但是,当我尝试向任何用户查询OneDrive文件( DriveItem )时,我得到一个空响应和资源未找到错误。 Same error when I use UserPrincipalName instead of Id . 当我使用UserPrincipalName而不是Id时,出现相同的错误。

sample request: 样品要求:

/v1.0/users/427d0a15-69db-4ab1-b7ae-542776ef53ed/drive/items

What is the call pattern for a Global Admin to query the drives/drive items of all users in the tenant? 全局管理员查询租户中所有用户的驱动器/驱动器项目的调用方式是什么?

I provided Admin Consent to the application already for these permissions: 我已经为这些权限提供了应用程序的管理员同意:

public static string[] Scopes = {
    "Files.ReadWrite.All",
    "Sites.Read.All",
    "Sites.ReadWrite.All",
    "Sites.FullControl.All",
    "User.ReadWrite.All",
    "Directory.ReadWrite.All",
    "Directory.AccessAsUser.All"
};

I am using Delegated Permissions and requesting permissions at runtime via the code using PublicClientApplication class if that matters. 我正在使用Delegated Permissions,并在运行时通过使用PublicClientApplication类的代码请求权限(如果重要)。

Update: I get the same "Resource Not Found" error when I call: 更新:致电时,我收到相同的“找不到资源”错误:

/v1.0/users/427d0a15-69db-4ab1-b7ae-542776ef53ed/drive/root/children

Source code: 源代码:

IGraphServiceUsersCollectionPage usersCollection =
   await graphClient.Users.Request().GetAsync();

foreach (User user in usersCollection)
{
   IDriveItemChildrenCollectionPage childrenCollection =
    await graphClient.Users[user.Id].Drive.Root.Children.Request().GetAsync();
}

When the Foreach loop iterates first time, the first user is the logged in Global Admin and the call to Drive.Root.Children works correctly, but on consequent iterations for other users, an exception is thrown with error message: 当Foreach循环第一次迭代时,第一个用户是登录的Global Admin,对Drive.Root.Children的调用可以Drive.Root.Children工作,但是在随后的其他用户迭代中,将引发异常并显示错误消息:

{"Code: itemNotFound\\r\\nMessage: The resource could not be found.\\r\\n\\r\\nInner error\\r\\n"} {“代码:itemNotFound \\ r \\ n消息:找不到资源。\\ r \\ n \\ r \\ n内部错误\\ r \\ n”}

You cannot call [/drive/items][1] directly. 您不能直接调用[/drive/items][1] You need to either provide a DriveItem.Id (ie /drive/items/{id} ) or a path (ie /drive/root/children ). 您需要提供DriveItem.Id (即/drive/items/{id} )或路径(即/drive/root/children )。

Try this instead: 尝试以下方法:

/v1.0/users/427d0a15-69db-4ab1-b7ae-542776ef53ed/drive/root/children

After days of trial and error I found out a workaround to the problem which I will post as an answer to help people having similar issues. 经过数天的反复试验,我找到了解决该问题的方法,并将其发布为答案,以帮助遇到类似问题的人们。 If a better solution is provided I will accept that answer, so the hunt is still on.. 如果提供更好的解决方案,我将接受该答案,因此搜寻仍在进行中。

It turns out that the Global O365 Admin does not by default have access to view OneDrive Business folders and files of other users in the tenant. 事实证明,默认情况下,全局O365管理员无权查看租户中的OneDrive业务文件夹和其他用户的文件。

What I had to do is: 我要做的是:

  1. Login as the Global Admin to O365 portal 以全局管理员身份登录到O365门户
  2. Go to Admin Center > Users 转到管理中心>用户
  3. For each User, expand OneDrive Settings and click on "Access files" This gives permissions to manage that user's OneDrive. 对于每个用户,展开“ OneDrive设置”,然后单击“访问文件”。这将授予管理该用户的OneDrive的权限。

After doing this: 完成此操作后:

/v1.0/users/427d0a15-69db-4ab1-b7ae-542776ef53ed/drive/root/children

returns properly all children of that users drive items! 正确返回该用户驱动项的所有子项!

I said I will accept a better answer, so to define better: 我说我会接受一个更好的答案,因此要定义更好:

  1. An answer that shows how to do this by code 显示如何通过代码执行此操作的答案

  2. Or an answer that at least shows how to do this with less clicks. 或答案至少可以说明如何减少点击次数。 Imagine if the tenant has 100K users, the global admin has to click that Access Files button for 100K users one by one! 想象一下,如果租户有10万个用户,那么全局管理员必须为10万个用户单击一个“访问文件”按钮! (no bulk settings option available) That s not a great experience and not a practical solution. (没有可用的批量设置选项)这不是很好的经验,也不是可行的解决方案。

Best answer would be: 1 + 2 :) 最好的答案是:1 + 2 :)

UPDATE: I found a better workaround, that is if I set the permissions in App Mod, as opposed to Delegated permissions/User Mod. 更新:我发现了一个更好的解决方法,那就是如果我在App Mod中设置了权限,而不是Delegated权限/ User Mod。 Then the app has access to all users' drives/files in One Drive and there is no need for the global admin to provide himself the permissions as such. 这样,该应用程序就可以访问一个驱动器中所有用户的驱动器/文件,并且无需全局管理员为其本身提供权限。 The enterprise admin would just need to give consent to the app only once in its lifetime in the enterprise tenant. 企业管理员只需要在应用程序的整个生命周期中在企业租户中同意一次即可。 With this update I will accept this answer. 通过此更新,我将接受此答案。

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

相关问题 使用Microsoft图表将文件上传到onedrive以进行业务 - Uploading file to onedrive for business using Microsoft graph Microsoft Graph - 搜索 OneDrive - Microsoft Graph - Searching OneDrive Microsoft Graph:将文件从URL [C#]上传到onedrive - Microsoft Graph: upload files to onedrive from URL [C#] 带有Service / Daemon应用程序的Microsoft Graph CSharp SDK和OneDrive for Business - Quota facet返回null - Microsoft Graph CSharp SDK and OneDrive for Business with a Service/Daemon application - Quota facet returns null OneDrive for Business的Microsoft Graph API是否可以过滤文件扩展名? - Does Microsoft Graph API for OneDrive for Business have the ability to filter on file extensions yet? 如何在 c# 中使用 Microsoft Graph Api 上传到 OneDrive - How to upload to OneDrive using Microsoft Graph Api in c# 使用 Microsoft graph API 获取 OneDrive 中的所有文件夹 - Fetch all the folders in OneDrive using Microsoft graph API 用于OneDrive的Microsoft Graph API响应服务不可用 - Microsoft Graph API for OneDrive responds with service not available Microsoft Graph 列出 OneDrive 项目的最大数量? - Microsoft Graph Maximum number for List OneDrive Items? Microsoft Graph .Net API:共享的OneDrive文件夹 - Microsoft Graph .Net API: Shared OneDrive folder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM