1

Subscribe to Watch Changes

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
  drive_id: string,
9
  webhook_address: string,
10
  channelId: any,
11
) {
12
  const SUPPORT_ALL_DRIVES = true;
13
  const SUPPORT_TEAM_DRIVES = true;
14
  const INCLUDE_ITEMS_FROM_ALL_DRIVES = true;
15
  const START_PAGE_URL = `https://www.googleapis.com/drive/v3/changes/startPageToken/?driveId=${drive_id}&supportsAllDrives=${SUPPORT_ALL_DRIVES}`;
16

17
  const token = gdrive_auth["token"];
18

19
  const response_sp = await fetch(START_PAGE_URL, {
20
    method: "GET",
21
    headers: {
22
      Authorization: "Bearer " + token,
23
      "Content-Type": "application/json",
24
    },
25
  });
26

27
  const start_page_result = await response_sp.json();
28
  const START_PAGE_TOKEN = start_page_result["startPageToken"];
29

30
  const WATCH_URL = `https://www.googleapis.com/drive/v3/changes/watch/?pageToken=${START_PAGE_TOKEN}&supportsAllDrives=${SUPPORT_ALL_DRIVES}&supportsTeamDrives=${SUPPORT_TEAM_DRIVES}&includeItemsFromAllDrives=${INCLUDE_ITEMS_FROM_ALL_DRIVES}`;
31

32
  const requestBody = {
33
    kind: "api#channel",
34
    type: "webhook",
35
    address: webhook_address,
36
    id: channelId,
37
  };
38

39
  const response = await fetch(WATCH_URL, {
40
    method: "POST",
41
    body: JSON.stringify(requestBody),
42
    headers: {
43
      Authorization: "Bearer " + token,
44
      "Content-Type": "application/json",
45
    },
46
  });
47

48
  const message = await response.json();
49

50
  return message;
51
}
52

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
      drive_id: string,
    7
      webhook_address: string,
    8
      channelId: any,
    9
    ) {
    10
      const SUPPORT_ALL_DRIVES = true;
    11
      const SUPPORT_TEAM_DRIVES = true;
    12
      const INCLUDE_ITEMS_FROM_ALL_DRIVES = true;
    13
      const START_PAGE_URL = `https://www.googleapis.com/drive/v3/changes/startPageToken/?driveId=${drive_id}&supportsAllDrives=${SUPPORT_ALL_DRIVES}`;
    14
    
    
    15
      const token = gdrive_auth["token"];
    16
    
    
    17
      const response_sp = await fetch(START_PAGE_URL, {
    18
        method: "GET",
    19
        headers: {
    20
          Authorization: "Bearer " + token,
    21
          "Content-Type": "application/json",
    22
        },
    23
      });
    24
    
    
    25
      const start_page_result = await response_sp.json();
    26
      const START_PAGE_TOKEN = start_page_result["startPageToken"];
    27
    
    
    28
      const WATCH_URL = `https://www.googleapis.com/drive/v3/changes/watch/?pageToken=${START_PAGE_TOKEN}&supportsAllDrives=${SUPPORT_ALL_DRIVES}&supportsTeamDrives=${SUPPORT_TEAM_DRIVES}&includeItemsFromAllDrives=${INCLUDE_ITEMS_FROM_ALL_DRIVES}`;
    29
    
    
    30
      const requestBody = {
    31
        kind: "api#channel",
    32
        type: "webhook",
    33
        address: webhook_address,
    34
        id: channelId,
    35
      };
    36
    
    
    37
      const response = await fetch(WATCH_URL, {
    38
        method: "POST",
    39
        body: JSON.stringify(requestBody),
    40
        headers: {
    41
          Authorization: "Bearer " + token,
    42
          "Content-Type": "application/json",
    43
        },
    44
      });
    45
    
    
    46
      const message = await response.json();
    47
    
    
    48
      return message;
    49
    }
    50