How to use the googleapis.google.drive function in googleapis

To help you get started, we’ve selected a few googleapis examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github thegazelle-ad / gazelle-server / deployment-resources / scripts / helpers / upload-database-dump.js View on Github external
function uploadDatabaseDump(auth) {
  const drive = google.drive({ version: 'v3', auth });
  // get file path from arguments
  const [, , inputFilePath] = process.argv;
  if (!inputFilePath) {
    console.error('Error: No filename was specified in arguments');
    process.exit(1);
  }

  drive.files.list(
    {
      q:
        "name='Database Dumps' and mimeType='application/vnd.google-apps.folder'",
    },
    (err, listFileResponse) => {
      if (err) {
        throw err;
      }
github cofacts / rumors-line-bot / src / handlers / fileHandler.js View on Github external
console.log('Google credentials not set, skip Gdrive initialization.');
    return;
  }

  const { token, secrets } = JSON.parse(process.env.GOOGLE_CREDENTIALS);

  // Authorize a client with the loaded credentials, then call the
  // Drive API.
  const clientSecret = secrets.installed.client_secret;
  const clientId = secrets.installed.client_id;
  const redirectUrl = secrets.installed.redirect_uris[0];
  const oauth2Client = new OAuth2(clientId, clientSecret, redirectUrl);

  // Check if we have previously stored a token.
  oauth2Client.setCredentials(token);
  drive = google.drive({ version: 'v3', auth: oauth2Client });
}
github asrivas / work-less-do-more / createSheet.js View on Github external
const main = async () => {
  const auth = await google.auth.getClient({ scopes: SCOPES });
  const sheets = google.sheets({ version: 'v4', auth });

  const token = (await fs.readFile('githubToken.json')).toString().trim();
  const octokit = new Octokit({ auth: `token ${token}` });

  const drive = google.drive({ version: 'v3', auth })

  await deleteAllFiles(drive);
  // const title = 'Statistics from GitHub and food survey for I/O talk';
  // let id = await checkForSheet(drive, title);
  // if (!id) {
  //     id = await createSpreadsheet(sheets, title);
  //     await writeHeader(sheets, id, 0);
  //     await addUser(drive, id, 'fhinkel.demo@gmail.com');
  //     await addUser(drive, id, 'GSuite.demos@gmail.com');
  // }
  // let cloneData = await numberOfClones(octokit);
  // await appendCloneData(sheets, id, cloneData);
}
github simont77 / fakegato-history / lib / googleDrive.js View on Github external
function getFileID(folder, name, cb) {
  var drive = google.drive('v3');
  // debug("GET FILE ID : %s/%s",folder,name);
  drive.files.list({
    q: "name = '" + name + "' and trashed = false and '" + folder + "' in parents",
    fields: 'files(id, name)',
    spaces: 'drive',
    // parents: [folder],
    auth: auth
  }, function(err, result) {
    // debug("GET FILE ID result",result,err);
    cb(err, result);
  });
}
github simont77 / fakegato-history / lib / googleDrive.js View on Github external
function getFolder(folder, cb) {
  var drive = google.drive('v3');
  //    debug("getFolder",folder);
  drive.files.list({
    q: "mimeType='application/vnd.google-apps.folder' and name = '" + folder + "' and trashed = false",
    fields: 'nextPageToken, files(id, name)',
    spaces: 'drive',
    auth: auth
  }, function(err, res) {
    if (err) {
      debug("getFolder - err", err);
      cb(err, folder);
    } else {
      if (res.data.files.length > 0) {
        if (res.data.files.length > 1) {
          debug("Multiple folders with same name, taking the first one", folder, 'in', res.data.files);
        }
        //      debug('Found Folder: ', res.files[0].name, res.files[0].id);
github NP-compete / Alternate-Authentication / Home / Gdrive / downloadAllDomains.js View on Github external
function downloadAllFilesFromTheGoogleDrive(auth){
const drive = google.drive({ version: 'v3', auth});
return new Promise((resolve,reject) => {
  drive.files.list({
      spaces: 'appDataFolder',
      fields: 'nextPageToken, files(id, name)',
      pageSize: 100
    }, function (err, res) {
        if (err) {
          console.error(err);
          reject(err);
        }else{
          let i = 0;
          for(let file of res.data.files) {

            if(file.name != '_init'){
            const dest = fs.createWriteStream(__dirname + '/gdriveCred/'+file.name);
github NP-compete / Alternate-Authentication / Home / Gdrive / updateId.js View on Github external
function updateIdCallback(auth, accountName, username, password, masterPassword){
 const drive = google.drive({ version: 'v3', auth});
 return new Promise((resolve,reject) => {
     updateAccountGdrive(drive,{
         name: accountName,
         username: username,
         password: password,
     },masterPassword).then(createdResult => {
         resolve(createdResult);
     }).catch(e => {
         reject(e);
     });
 });
}
github reruin / sharelist / plugins / drive.gda.js View on Github external
const checkAuth = async (client_id, client_secret, code) => {
    let key = `${client_id}:${client_secret}`
    const oauth2 = clientMap[key]

    let res = await oauth2.getToken(code)
    if (res.tokens) {
      saveAuth(key , res.tokens)
      oauth2.setCredentials(res.tokens)
      driveMap[key] = google.drive({ version: 'v3', oauth2 })
      return res.tokens
    } else {
      return false
    }
  }
github The-Politico / gootenberg / src / index.js View on Github external
constructor() {
    this.sheetsAPI = google.sheets('v4');
    this.driveAPI = google.drive('v3');
    this.docsAPI = google.docs('v1');
  }
github gsuitedevs / md2googleslides / src / slide_generator.js View on Github external
static async copyPresentation(oauth2Client, title, presentationId) {
        let drive = google.drive({ version: 'v3', auth: oauth2Client});
        let res = await drive.files.copy({
            fileId: presentationId,
            resource: {
                name: title
            }
        });
        return SlideGenerator.forPresentation(oauth2Client, res.data.id);
    }