如何在 MS Graph 中检索 DriveItems 的自定义列 [英] How To Retrieve Custom Columns For DriveItems in MS Graph
问题描述
我正在尝试使用 Graph API 来检索 Sharepoint 文档库中的文件层次结构.由于文档库存储在驱动器"中(在技术上将其称为 OneDrive 是否正确?),我使用 /drives
端点来获取文件列表,如下所示:
I'm trying to use the Graph API to retrieve a hierarchy of files in a Sharepoint document library. Since document libraries are stored in "drives" (is it technically correct to call it OneDrive?), I'm using the /drives
endpoint to fetch a list of files, like this:
https://graph.microsoft.com/beta/drives/{driveid}/root/children
我想从通过 Sharepoint 查看这些项目时存在的一些自定义列中获取信息.使用 ?expand=fields
不起作用,因为 fields
仅存在于 /sites
端点的 listItem 对象中,而不存在于 driveItem
对象.如果我尝试从单个 driveItem 获取 listItem(将 Graph 从 OneDrive 遍历到 Sharepoint),然后扩展字段,例如/drives
端点的
I would like to get information from some of the custom columns that exist when viewing these items through Sharepoint. Using ?expand=fields
doesn't work because fields
only exists in listItem object of the /sites
endpoint, not in the driveItem
object of /drives
endpoint. If I try obtaining the listItem from a single driveItem (traversing the Graph from OneDrive to Sharepoint), and then expanding the fields, like
https://graph.microsoft.com/beta/drives/{driveid}/items/{driveItemId}/listItem?expand=fields
这会检索内置列(Author、DocIcon 和其他一些),但似乎不会检索自定义列.我还尝试从 /sites
端点获取文件列表,并使用 ?expand=fields
将获取自定义列,但它会从每个子文件夹中获取每个文件,而不是当前文件夹路径.但我觉得这值得自己提出这样的问题.
this retrieves built-in columns (Author, DocIcon, and some others) but doesn't seem to retrieve the custom columns.
I've also tried getting the list of files from the /sites
endpoint, and using ?expand=fields
will get the custom columns, but it gets every file from every subfolder, rather than the current folder path. But I feel that deserves its own SO question.
是否可以从 driveItems 检索自定义列信息?
Is it possible to retrieve custom column information from driveItems?
推荐答案
我做了一些测试.应该起作用的是:
I did some testing. What SHOULD work is:
https://graph.microsoft.com/beta/drives/{driveid}/root/children?$select=id,MyCustomColumnName
但是,当我这样做时,它只是返回了那个 id 字段.在我看来,这是图表中的一个错误,因为这种相同类型的查询在 SharePoint REST api 中确实有效.
However, when I did that, it just returned that id field. In my opinion, that is a bug in the graph because this same type of query does work in the SharePoint REST api.
如果这有帮助,您可以使用 SharePoint REST api 完成此操作.您的端点查询将类似于:
If this helps, you can accomplish this by using the SharePoint REST api. Your endpoint query would be something like:
https://{yoursite}.sharepoint.com/sites/{sitename}/_api/web/lists/('{DocumentLibraryID}')/items?$select=id,MyCustomColumnName
还有其他方法可以执行相同的查询.
There are other ways to do the same query.
这篇关于如何在 MS Graph 中检索 DriveItems 的自定义列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!