Get Changes ( gdrive)
One script reply has been approved by the moderators Verified

Created by rossmccrann 193 days ago Viewed 245 times 1 Point

No comments yet

Login to be able to comment
Points: 0
deno
One script reply has been approved by the moderators
Ap­pro­ved
import * as wmill from 'https://deno.land/x/windmill@v1.27.2/mod.ts'

export async function main(gdrive_auth: wmill.Resource<"gdrive">) {
  const START_PAGE_URL =
    `https://www.googleapis.com/drive/v3/changes/startPageToken/`;

  let last_start_page_token: string | undefined = await wmill.getInternalState();

const token = gdrive_auth["token"];

if (last_start_page_token == undefined){
 const START_PAGE_URL =
    `https://www.googleapis.com/drive/v3/changes/startPageToken`;
 
  const response_sp = await fetch(START_PAGE_URL, {
    method: "GET",
    headers: {
      Authorization: "Bearer " + token,
      "Content-Type": "application/json",
    },
  });
  const start_page_result = await response_sp.json();

  last_start_page_token = start_page_result["startPageToken"];
}

  const CHECK_CHANGES_URL =
    `https://www.googleapis.com/drive/v3/changes/?pageToken=${last_start_page_token}`;

  const changes_response = await fetch(CHECK_CHANGES_URL, {
    method: "GET",
    headers: {
      Authorization: "Bearer " + token,
      "Content-Type": "application/json",
    },
  });

  const result_changes = await changes_response.json();

  await wmill.setInternalState(result_changes['newStartPageToken']);

  return result_changes["changes"];
}

Submitted by rossmccrann 193 days ago

Edited 184 days ago

No comments yet

Login to be able to comment