Socket
Socket
Sign inDemoInstall

easy-google-drive

Package Overview
Dependencies
63
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    easy-google-drive

Easy NodeJS Google Drive API Auth in Promise way


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Easy Google Drive

Easy NodeJS Google Drive API Auth in Promise way

Why

Handling Google Drive API Authentication is not an easy task, with a lot of callbacks and token operations.

This scripts aims to ease this process.

Usage

First of all, you need a client_secrets.json. Check Google doc for it: [https://developers.google.com/drive/v3/web/quickstart/nodejs] (Step 1)

Then, you can use this library in this way:

const EDrive = require('./simple-google-drive').EasyDrive
const fs = require('fs')
const Promise = require('bluebird').Promise
const readFile = Promise.promisify(require("fs").readFile);


function init() {
    readFile('client_secret.json')
        .then(raw => JSON.parse(raw))
        .then(secrets =>  EDrive.fromSecrets(secrets))
        .then(eDrive => listFiles(eDrive))
        .then(_ => console.log("Done"))
        .catch(err => console.error(err))
}

function listFiles(eDrive) {
    console.log("Entering listFiles")
    eDrive.drive.files.list({
      auth: eDrive.auth,
      pageSize: 10,
      fields: "nextPageToken, files(id, name)"
    }, function(err, response) {
      if (err) {
        console.log('The API returned an error: ' + err);
        return;
      }
      var files = response.files;
      if (files.length == 0) {
        console.log('No files found.');
      } else {
        console.log('Files:');
        for (var i = 0; i < files.length; i++) {
          var file = files[i];
          console.log('%s (%s)', file.name, file.id);
        }
      }
    });
  }

init();

FAQs

Last updated on 16 Jan 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc