Get contents of a Google Doc using the Google Drive API

Example of getting the contents of a Google Doc via the Google Drive REST API in javascript.

Get contents of a Google Doc using vanilla javascript

let fetch_url = `https://www.googleapis.com/drive/v3/files/${fileID}/export?mimeType=text/plain`;
let folder_fetch_options = {
  method: "GET",
  headers: {
    Authorization: `Bearer ${token}`,
    "Content-Type": "application/json",
  },
};

const response = await fetch(fetch_url, folder_fetch_options);
// Text will be a string representation of the Google Doc
const text = await response.text();

For other Google Drive API Examples: https://www.mikesallese.me/tags/google-drive-api-examples