1

Download Files (Google Docs, Sheets, Slides)

by
Published Jul 26, 2022
Script gdrive Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 6 days ago
1
//native
2

3
type Gdrive = {
4
  token: string;
5
};
6
export async function main(
7
  gdrive_auth: Gdrive,
8
  fileId: string,
9
  mimeType: string,
10
) {
11
  const DOWNLOAD_FILE_URL = `https://www.googleapis.com/drive/v3/files/fileId=${fileId}/export/?mimeType=${mimeType}`;
12

13
  const token = gdrive_auth["token"];
14

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

23
  const result = await response.json();
24

25
  return result;
26
}
27

Other submissions
  • Submitted by rossmccrann Deno
    Created 398 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