create_oauth_token.js
function getNewToken(credentials, oauth2Client, callback) {
    var authUrl = oauth2Client.generateAuthUrl({
        access_type: 'offline',
        scope: SCOPES
    });
    console.log('Authorize this app by visiting this url: ', authUrl);
    var rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    rl.question('Enter the code from that page here: ', function(code) {
        rl.close();
        oauth2Client.getToken(code, function(err, token) {
            if (err) {
                console.log('Error while trying to retrieve access token', err);
                return;
            }
            oauth2Client.credentials = token;
            storeToken(credentials, token);
            callback(oauth2Client);
        });
    });
}
function getNewToken(credentials, oauth2Client, callback) {
    var authUrl = oauth2Client.generateAuthUrl({
        access_type: 'offline',
        scope: SCOPES
    });
    console.log('Authorize this app by visiting this url: ', authUrl);
    var rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    rl.question('Enter the code from that page here: ', function(code) {
        rl.close();
        oauth2Client.getToken(code, function(err, token) {
            if (err) {
                console.log('Error while trying to retrieve access token', err);
                return;
            }
            oauth2Client.credentials = token;
            storeToken(credentials, token);
            callback(oauth2Client);
        });
    });
}
function getNewToken ( credentials , oauth2Client , callback ) { var authUrl = oauth2Client . generateAuthUrl ( { access_type : 'offline' , scope : SCOPES } ) ; console . log ( 'Authorize this app by visiting this url: ' , authUrl ) ; var rl = readline . createInterface ( { input : process . stdin , output : process . stdout } ) ; rl . question ( 'Enter the code from that page here: ' , function ( code ) { rl . close ( ) ; oauth2Client . getToken ( code , function ( err , token ) { if ( err ) { console . log ( 'Error while trying to retrieve access token' , err ) ; return ; } oauth2Client . credentials = token ; storeToken ( credentials , token ) ; callback ( oauth2Client ) ; } ) ; } ) ; }
Get and store new token after prompting for user authorization, and then
execute the given callback with the authorized OAuth2 client.

@param {Object} credentials The authorization client credentials.
@param {google.auth.OAuth2} oauth2Client The OAuth2 client to get token for.
@param {getEventsCallback} callback The callback to call with the authorized
client.
Get and store new token after prompting for user authorization and then execute the given callback with the authorized OAuth2 client .