Get google doc description using googleapis in nodejs

Viewed 54

I am exploring google api to find out a file description, which is a short summary of google drive file.

enter image description here

So I have came up with this code:

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

  const docs = google.docs({
    version: "v1",
  });

  // set keys and docid
  // clientEmail, privateKey, documentid

  const jwt = new google.auth.JWT(clientEmail, null, privateKey, scopes);

  const response = await docs.documents.get({
    auth: jwt,
    documentId: documentId,
  });

The response returning an object but it is does not contain description. Any ideas how to find that through the 'googleapis' ?

1 Answers

I'm sure Docs API has this option. However, I know you can get that information using Drive API with the method Files: get and using the parameter 'fields':'description' or you can use the method Files: list with the parameter 'fields': 'files(description)' if you wanted to list the files with the description already on it.

Method Files: list

function execute() {
    return gapi.client.drive.files.list({
      "corpora": "user",
      "q": "'folder_ID' in parents",
      "supportsAllDrives": true,
      "supportsTeamDrives": true,
      "fields": "files(description, id, name)"
    })

Method Files:get

function execute() {
    return gapi.client.drive.files.get({
        'fileId': 'file_ID',
        'fields':'description, id, name'
    })

Reference:

Related