如何在 MS Graph 中检索 DriveItems 的自定义列

Ada*_*unn 6 sharepoint onedrive microsoft-graph-api

我正在尝试使用 Graph API 检索 Sharepoint 文档库中的文件层次结构。由于文档库存储在“驱动器”中(将其称为 OneDrive 在技术上是否正确?),我使用端点/drives来获取文件列表,如下所示:

https://graph.microsoft.com/beta/drives/{driveid}/root/children
Run Code Online (Sandbox Code Playgroud)

我想从通过 Sharepoint 查看这些项目时存在的一些自定义列中获取信息。使用?expand=fields不起作用,因为fields仅存在于端点的 listItem 对象中/sites,而不存在于端点driveItem的对象中/drives。如果我尝试从单个driveItem获取listItem(从OneDrive遍历图表到Sharepoint),然后扩展字段,例如

https://graph.microsoft.com/beta/drives/{driveid}/items/{driveItemId}/listItem?expand=fields
Run Code Online (Sandbox Code Playgroud)

这会检索内置列(Author、DocIcon 和其他一些列),但似乎不会检索自定义列。我还尝试从端点获取文件列表/sites,并使用?expand=fields将获取自定义列,但它从每个子文件夹获取每个文件,而不是当前文件夹路径。但我觉得这值得有一个自己的问题。

是否可以从driveItems 检索自定义列信息?

小智 8

我花了很多时间挖掘不同的语法可能性,最终能够使用这种查询格式获取自定义库属性。这是唯一为文档库生成自定义/用户定义字段的工具。

https://graph.microsoft.com/v1.0/drives/insert_drive_id_here/root/children?expand=listItem

缩短结果:

{
"@odata.context": "...",
"value": [
        {
        "@microsoft.graph.downloadUrl": "...",
        "listItem@odata.context": "...",
        "listItem": {
            "@odata.etag": "...",
            "fields@odata.context": "...",
            "fields": {
                "@odata.etag": "...",
                "Title": "...",
                "Other_Custom_Property": "..."
                }
            }
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)


Gre*_*ina 2

我做了一些测试。应该起作用的是:

https://graph.microsoft.com/beta/drives/{driveid}/root/children?$select=id,MyCustomColumnName

然而,当我这样做时,它只是返回了那个 id 字段。在我看来,这是图中的一个错误,因为这种相同类型的查询确实可以在 SharePoint REST api 中工作。

如果这有帮助,您可以使用 SharePoint REST api 来完成此操作。您的端点查询将类似于:

https://{yoursite}.sharepoint.com/sites/{sitename}/_api/web/lists/(' {DocumentLibraryID}')/items?$select=id,MyCustomColumnName

还有其他方法可以执行相同的查询。

  • 为了尝试继续使用 Graph API,我最终查询了 Drives API,以选择文件“/drives/{driveId}/root/children?select=sharepointIds,name”的 Sharepoint ID,然后使用该 Sharepoint 列表项Sites API 上的 ID `/sites/root/sites/{sitePath}/lists/{listId}/items/{listItemId}?expand=fields&select=fields` (3认同)