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

如何通过Microsoft Graph API获取DriveItem的Audio facet及相关字段?

解决Microsoft Graph API无法获取DriveItem的audio字段内容问题

当使用Graph API的search端点查询DriveItem时,仅通过select指定audio字段不足以获取其内部的title、artist等属性——默认情况下嵌套属性不会被自动展开,需要通过$expand参数显式声明展开audio,同时可以在select中指定需要的子字段来优化返回结果。

修改后的代码示例

LinkedList<Option> requestOptions = new LinkedList<>();
// 指定需要的字段,包括audio的子字段
requestOptions.add(new QueryOption("select", "name,id,audio(title,artist)"));
// 显式展开audio属性
requestOptions.add(new QueryOption("expand", "audio"));

return MicrosoftGraphHelper.getClient()
        .me()
        .drive()
        .root()
        .search(DriveItemSearchParameterSet.newBuilder().withQ(".mp3").build())
        .buildRequest(requestOptions)
        .getAsync();

对应的Graph API请求

https://graph.microsoft.com/v1.0/me/drive/root/search(q='.mp3')?select=name,id,audio(title,artist)&expand=audio

说明

  • $expand=audio:告知API需要展开audio嵌套对象,而不是只返回引用或null
  • select=audio(title,artist):明确指定需要获取audio下的title和artist字段,避免返回不必要的冗余数据,提升请求效率

这样修改后,返回的DriveItem对象中audio字段就会包含你需要的元数据信息。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 18:33:09