Calling Google Drive API returns Invalid_grant OAuth2
<p><strong>SOLVED!</strong></p>

<p>The problem was not my code. I'd manually set the time on my Linux Server, which meant that Google's server refused giving me access. I used following command on my Server to set time: <code>ntpdate 0.europe.pool.ntp.org</code></p>

<p><strong>Original Issue:</strong></p>

<p>I'm currently trying to develop a small script in NodeJS, which reads some values from a Google Spreadsheet, and write it to a file in JSON format. </p>

<p>The code is functioning without any problems on my Mac, but after upload to a Ubuntu 14.04.4, some of the functions from the 'google-spreadsheet' module is not working and returns undefined.</p>

<p>I'm not 100% sure, whether there is a problem with the node module, or if there is something wrong with my code.</p>

<p>The code which does the call:</p>

<pre><code>var GoogleSpreadsheet = require('google-spreadsheet');
var fs = require('fs');

function scheduleBidding(sheetSecretKey) {
    this.sheetKey = sheetSecretKey;
}

scheduleBidding.prototype.getBiddingHeaders = function (filePrefix) {
var doc = new GoogleSpreadsheet(this.sheetKey);
var sheet;
var daysSinceYearStart = getDaysIntoYear();
var localSheetKey = this.sheetKey;
var biddingObject = new Object();
var filePath = filePrefix+"staticConfigFiles/googleApiKey";
console.log(filePath);
fs.readFile(filePath, 'utf8', function (err, data) {
    creds = JSON.parse(data);
    console.log(creds);
    doc.useServiceAccountAuth(creds, function (err) {
        if(err) throw err;
        doc.getInfo(function (err, info) {
            if(err) throw err;
            console.log(info);
            sheet = info.worksheets[0];
            var numberOfColumns = sheet.colCount;
            sheet.getCells({
                'min-row': 1,
                'max-row': 1,
                'min-col': 2,
                'max-col': numberOfColumns,
                'return-empty': true
            }, function(err, cells) {
                sheet.getRows({
                    offset: 1,
                    limit: 366
                }, function( err, rows ){
                    yesterdaysBid = rows[daysSinceYearStart-2];
                    todaysBidding = rows[daysSinceYearStart-1];
                    cells.forEach(function (listItem, indexArray) {
                        columnName = cells[indexArray].value;
                        var functionName = String(columnName.toLowerCase());
                        functionName = functionName.replace(/\s/g, '').replace(":", "");
                        biddingObject[columnName] = {
                            "yesterdaysBid": yesterdaysBid[functionName],
                            "todaysBid": todaysBidding[functionName]
                        };
                        newFileName = filePrefix+"scheduleData/"+localSheetKey+".json";
                        prettyJson = JSON.stringify(biddingObject);
                        fs.writeFile(newFileName, prettyJson);
                        console.log("ScheduleBidding JSON has been updated");
                    });
                });
            });
        });
    });
});

function getDaysIntoYear() {
    var todaysDate = new Date();
    var daysAgo;

    //
    returnDays = parseInt(todaysDate.getDate())+daysAgo;
    return returnDays;
}
};
</code></pre>

<p>I recieve the following exception when I execute the script on my Ubuntu server:</p>

<pre><code>    Error: invalid_grant
www-0     at Request._callback (/SomePath/node_modules/google-spreadsheet/node_modules/google-auth-library/node_modules/gtoken/lib/index.js:215:34)
www-0     at Request.self.callback (/SomePath/node_modules/google-spreadsheet/node_modules/google-auth-library/node_modules/gtoken/node_modules/request/request.js:187:22)
www-0     at Request.EventEmitter.emit (events.js:98:17)
www-0     at Request.&lt;anonymous&gt; (/SomePath/node_modules/google-spreadsheet/node_modules/google-auth-library/node_modules/gtoken/node_modules/request/request.js:1044:10)
www-0     at Request.EventEmitter.emit (events.js:95:17)
www-0     at IncomingMessage.&lt;anonymous&gt; (/SomePath/node_modules/google-spreadsheet/node_modules/google-auth-library/node_modules/gtoken/node_modules/request/request.js:965:12)
www-0     at IncomingMessage.EventEmitter.emit (events.js:117:20)
www-0     at _stream_readable.js:920:16
www-0     at process._tickDomainCallback (node.js:459:13)
</code></pre>

<p>Thanks in advance for the help. Let me know, if any information is missing.</p>