title: Authenticating Google Sheet API on Heroku using NodeJS
body: <p>I'm following this example to access the Google Sheets API:</p>
  
  <p><a href="https://developers.google.com/sheets/api/quickstart/nodejs" rel="noreferrer">https://developers.google.com/sheets/api/quickstart/nodejs</a></p>
  
  <p>Within the example code is the following method to fetch a new oauth token.</p>
  
  <pre><code>function getNewToken(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(token);
        callback(oauth2Client);
      });
    });
  }
  </code></pre>
  
  <p>This works fine on my local machine (manually visiting the page as prompted in the terminal, and entering the code in the command line). But this seems unpractical and doesn't work on Heroku. Is there any way to automate this? Maybe by fetching the URL (and token) in the nodeJS application and storing this somehow?</p>
  
  <p>Thanks in advance.</p>