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

使用msgraph-sdk Python包获取驱动器根目录子项:升级后报错求助

使用msgraph-sdk Python 1.0.0a11获取驱动器根目录子项的解决方案

在1.0.0a11版本中,Microsoft Graph Python SDK的API结构进行了调整,原版本里root.children的写法不再适用,需要改为通过root.items来访问根目录的子项。

核心替换代码

children = await self.app_client.drives.by_id(drive.id).root.items.get()

带查询参数的进阶用法

如果需要对返回结果做筛选、分页或指定返回字段,可以传入查询参数配置:

from msgraph.generated.drives.item.root.items.items_request_builder import ItemsRequestBuilder

# 定义查询参数:指定返回字段、限制返回条数
query_params = ItemsRequestBuilder.ItemsRequestBuilderGetQueryParameters(
    select=["name", "id", "size", "lastModifiedDateTime"],
    top=10
)

request_config = ItemsRequestBuilder.ItemsRequestBuilderGetRequestConfiguration(
    query_parameters=query_params
)

# 发起请求
children = await self.app_client.drives.by_id(drive.id).root.items.get(request_configuration=request_config)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.25 14:34:55