You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Microsoft Graph获取SharePoint文档库的元数据(列)

获取SharePoint文档库已定义列的方法

你之前调用/drives/{drive_id}只能拿到驱动器的基础信息,因为文档库的字段(列)实际存储在对应的List对象里,得通过关联的List来获取字段信息。具体步骤如下:

1. 获取文档库对应的List ID

每个SharePoint文档库(Drive)都关联着一个List,先调用接口拿到这个List的ID:

graph = f"https://graph.microsoft.com/v1.0/sites/root/drives/{drive_id}/list"
response = requests.get(graph, headers={'Authorization': access_token, 'Content-Type': 'application/json'})
list_info = response.json()
list_id = list_info['id']

这个请求返回的JSON里包含List的基础信息,其中id就是后续要用的List ID。

2. 获取List的所有字段(列)

用拿到的List ID调用接口,获取该文档库的所有已定义字段:

graph = f"https://graph.microsoft.com/v1.0/sites/root/lists/{list_id}/fields"
response = requests.get(graph, headers={'Authorization': access_token, 'Content-Type': 'application/json'})
fields = response.json()['value']

返回的value数组里每个元素对应一个字段,关键属性包括:

  • displayName:列的显示名称(比如你代码里的"Client")
  • internalName:列的内部名称(更新元数据时需要用这个,比如你代码里的"Date_x0020_de_x0020_facturation")
  • type:字段的数据类型(比如DateTime、Text、Boolean),方便你对应设置正确的数值格式

3. 筛选自定义字段(可选)

如果只需要自己定义的列(排除系统默认字段),可以根据isCustom属性过滤:

custom_fields = [field for field in fields if field.get('isCustom') is True]

这样你就能拿到文档库所有已定义的列信息,后续更新元数据时就可以准确使用对应的内部名称了。

内容的提问来源于stack exchange,提问作者RichardW

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 06:12:41