简体   繁体   中英

google docs api documents.get multiple fields ? (nodejs)

How can I select multiple fields when using the documents.get ?

Right now I am getting the documenmt like this:

  const doc = await docs.documents.get({
    documentId: copiedFile.data.id,
    fields: 'body/content'
  });

which returns this:

"data": {
  "body": {
    "content": [...]
  }
}

However, I need to also get the inlineObject and the only way so far I have been able to do so, is by removing the fields proeprty completely

  const doc = await docs.documents.get({
    documentId: copiedFile.data.id,
  });

Then I get this:

"data": {
  "title": "Some document title",
  "body": {
    "content": [...]
  },
  "headers": {
  },
  "footers": {
  },
  "documentStyle": {
  },
  "namedStyles": {
  },
  "lists": {
  },
  "revisionId": "some-long-id",
  "suggestionsViewMode": "SUGGESTIONS_INLINE",
  "inlineObjects": {
  },
  "documentId": "some-long-id"
}

But I am really only interested in data.body.content and data.inlineObjects When selecting everything the response is many thousands of lines of json larger, which I don't want.

I have tried fields: ['body/content', 'inlineObjects'] but that only returns body.content and not the inlineObjects - also the documentation doesn't mention this syntax anywhere, it was just to experiment.

I think it doesn't return any inlineObjects when you don't have any inlineObjects in the document. To confirm if the actual format is working and the statement above is true, try using other fields where a value is confirmed to be returned such as revisionId or title .

Test:

const doc = await docs.documents.get({
  documentId: copiedFile.data.id,
  fields: 'body/content,inlineObjects'
});

Output:

输出

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM