1
Download Files (Google Docs, Sheets, Slides)
One script reply has been approved by the moderators Verified
Created by rossmccrann 627 days ago Viewed 4205 times
0
Submitted by rossmccrann Deno
Verified 627 days ago
1
type Gdrive = {
2
  token: string;
3
};
4
export async function main(
5
  gdrive_auth: Gdrive,
6
  fileId: string,
7
  mimeType: string,
8
) {
9
  const DOWNLOAD_FILE_URL = `https://www.googleapis.com/drive/v3/files/fileId=${fileId}/export/?mimeType=${mimeType}`;
10

11
  const token = gdrive_auth["token"];
12

13
  const response = await fetch(DOWNLOAD_FILE_URL, {
14
    method: "GET",
15
    headers: {
16
      Authorization: "Bearer " + token,
17
      "Content-Type": "application/json",
18
    },
19
  });
20

21
  const result = await response.json();
22

23
  return result;
24
}
25