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

Node.js调用Google Docs API的documents.get如何选择多个返回字段

Google Docs API documents.get 多字段筛选配置方案

核心原因

你之前传数组格式的fields参数不符合Google API的参数约定,所以只能生效第一个字段。Google API的字段筛选参数要求传入英文逗号分隔的字段路径字符串,而非数组。

正确配置方式

直接将fields参数设为字符串'body/content,inlineObjects'即可同时返回两个目标字段,不会返回额外冗余内容。

Node.js 调用示例(基于googleapis官方库)

const { google } = require('googleapis');

// 已完成身份认证的docs客户端实例
const docsClient = google.docs({
  version: 'v1',
  auth: 你的身份认证实例 // 支持OAuth2客户端、服务账号密钥等认证方式
});

async function getTargetDocData(documentId) {
  const response = await docsClient.documents.get({
    documentId: documentId,
    fields: 'body/content,inlineObjects' // 逗号分隔的字符串,不要传数组
  });
  return response.data;
}

验证说明

调用后返回的响应数据只会包含body.content和inlineObjects两个顶层字段,无多余冗余内容,符合性能需求。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.25 00:54:04