【问题标题】:List children API doesn't give all the children of the drive/folder列出子 API 不会提供驱动器/文件夹的所有子项
【发布时间】:2017-10-11 11:36:55
【问题描述】:

我在获取用户 OneDrive 的文件/文件夹时遇到以下问题。

击球时

https://graph.microsoft.com/v1.0/users/{user-id}/drive

我在回复中得到了这个:

"quota": { "deleted": 0, "remaining": 0, "total": 0, "used": 0 }

表示驱动器未被使用或为空。

击球时 https://graph.microsoft.com/v1.0/users/{user-id}/drive/root 我得到了回应 -

"folder": {
    "childCount": 21
},
"root": {},
"size": 281236319

这里表示驱动器的根文件夹中有21个文件/文件夹,它们占用了281.23 MB的空间。

现在,点击https://graph.microsoft.com/v1.0/users/{user-id}/drive/root/children 我在响应中得到空向量 -

{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('user-id')/drive/root/children",
"value": []

}

驱动器中存在文件。但我无法通过儿童 API 获得它们。 任何帮助理解这 3 个不同的结果并获得响应将不胜感激

谢谢。

【问题讨论】:

    标签: rest microsoft-graph-api onedrive children


    【解决方案1】:

    此问题是由于使用不正确的 URL 调用引起的。文档并没有说得很清楚,但是 URL:

    https://graph.microsoft.com/v1.0/me/drive

    如果“驱动器”实际上是共享点实例的一部分,则不起作用。虽然 UI 在以用户身份登录时显示“Drive”,但 URL 包含对共享点的引用。

    正确使用的url其实是:

    https://{tenant}-my.sharepoint.com/_api/v2.0/drives/{drive id}/root/

    【讨论】:

      【解决方案2】:

      一旦您的用户通过身份验证并且您代表该用户检索访问令牌。你可以简单地调用这个端点:

      https://graph.microsoft.com/v1.0/me/drive/root/children
      

      您可能还想查看该用户 OneDrive 上的文件夹:

      https://graph.microsoft.com/v1.0/me/drive/root:{/Folder-Path}:/children
      

      您的 URL 也是正确的,应该可以正常工作,因为我刚刚使用我的“用户 ID”进行了测试,并且能够在我的 onedrive 中检索文件。

      https://graph.microsoft.com/v1.0/users/{user-id}/drive/root/children
      

      参考文献:

      https://stackoverflow.com/a/46614072/6559330 https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/driveitem_list_children

      【讨论】:

      • 是的,我知道 URL 是正确的。我的问题是,在点击驱动器/根 API 时,它显示该文件夹有 21 个子级,但在同一文件夹前点击 /children API 时,它返回一个空数组
      【解决方案3】:

      您必须使用范围 Files.Read.AllFiles.ReadWrite.All。这样做,您的请求将不再返回空数组。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-08-06
        • 1970-01-01
        • 2019-07-21
        • 1970-01-01
        • 1970-01-01
        • 2020-07-02
        • 2021-04-11
        相关资源
        最近更新 更多