Andre M Andre M -4 years ago 140
Node.js Question

Fetching files from Google Drive, from command-line in Node.js?

To facilitate updating of content on our information screen, we are looking at putting the content on Google Drive and then allowing the content to be synced via a NodeJS based application.

At the moment I am trying to test this approach using folder shared from my own account.

What I have so far, based on the documentation at :

var google = require('googleapis');
var OAuth2 = google.auth.OAuth2;
var readline = require('readline');

const CLIENT_ID = '';
const CLIENT_SECRET = '7h3c13n7s3cr37';
const REDIRECT_URL = '';

var oauth2Client = new OAuth2(

var scopes = [

var url = oauth2Client.generateAuthUrl({
access_type: 'offline', // 'online' (default) or 'offline' (gets refresh_token)
scope: scopes // If you only need one scope you can pass it as string

console.log('past following URL into a web browser');

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout

rl.question('Provide Key generated on web page ', (answer) => {

// store response key in file?

var drive ={ version: 'v2', auth: oauth2Client });

var folderId = 'mif01d3r';

auth: answer,
folderId: folderId,
}, function(error, response) {
if (error) {
console.log('err: ', error);


The current issue here is that the value for 'REDIRECT_URL' does not seem suitable. What should I be putting here for a command line application?

Answer Source is more for Python, but the below is applicable to all "Installed Applications"


This value signals to the Google Authorization Server that the authorization code should be returned in the title bar of the browser, with the page text prompting the user to copy the code and paste it in the application. This is useful when the client (such as a Windows application) cannot listen on an HTTP port without significant client configuration.

See also:

so it should be:

const REDIRECT_URL = 'urn:ietf:wg:oauth:2.0:oob';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download