title: How to generate authentication credentials for Google Sheets API?
body: <p>Step 1 (completed):</p>
  
  <p>As instructed, I have followed every step in Google's Node.js Quickstart:
  <a href="https://developers.google.com/sheets/api/quickstart/nodejs" rel="nofollow noreferrer">https://developers.google.com/sheets/api/quickstart/nodejs</a>
  and it ran perfectly without any errors. My understanding was that after I run index.js, a token.json is created. After which, I can somehow use the token.json for any future authentication purpose without needing credentials.json every time. Please, correct me if I am wrong in this assumption. I am only making this assumption based on what Google is saying in the previously given link - "Authorization information is stored on the file system, so subsequent executions will not prompt for authorization."</p>
  
  <p>Step 2 (problem):</p>
  
  <p>Below is another code snippet is given by a Google Sheet's API's documentation page for reading multiple range data:
  <a href="https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/batchGet" rel="nofollow noreferrer">https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/batchGet</a></p>
  
  <p>I, however, do not know how to generate authentication credentials for authClient. Am I suppose to do something with token.json? If yes, what is the protocol of using the token.json file?</p>
  
  <p>Please feel free to ask any follow-up questions if needed.</p>
  
  <pre><code>  enter code here// BEFORE RUNNING:
      // ---------------
      // 1. If not already done, enable the Google Sheets API
      //    and check the quota for your project at
      //    https://console.developers.google.com/apis/api/sheets
      // 2. Install the Node.js client library by running
      //    `npm install googleapis --save`
  
      const {google} = require('googleapis');
      var sheets = google.sheets('v4');
  
      authorize(function(authClient) {
        var request = {
          // The ID of the spreadsheet to retrieve data from.
          spreadsheetId: 'my-spreadsheet-id',  // TODO: Update placeholder value.
  
          // The A1 notation of the values to retrieve.
          ranges: [],  // TODO: Update placeholder value.
  
          // How values should be represented in the output.
          // The default render option is ValueRenderOption.FORMATTED_VALUE.
          valueRenderOption: '',  // TODO: Update placeholder value.
  
          // How dates, times, and durations should be represented in the output.
          // This is ignored if value_render_option is
          // FORMATTED_VALUE.
          // The default dateTime render option is [DateTimeRenderOption.SERIAL_NUMBER].
          dateTimeRenderOption: '',  // TODO: Update placeholder value.
  
          auth: authClient,
        };
  
        sheets.spreadsheets.values.batchGet(request, function(err, response) {
          if (err) {
            console.error(err);
            return;
          }
  
          // TODO: Change code below to process the `response` object:
          console.log(JSON.stringify(response, null, 2));
        });
      });
  
      function authorize(callback) {
        // TODO: Change placeholder below to generate authentication credentials. See
        // https://developers.google.com/sheets/quickstart/nodejs#step_3_set_up_the_sample
        //
        // Authorize using one of the following scopes:
        //   'https://www.googleapis.com/auth/drive'
        //   'https://www.googleapis.com/auth/drive.file'
        //   'https://www.googleapis.com/auth/drive.readonly'
        //   'https://www.googleapis.com/auth/spreadsheets'
        //   'https://www.googleapis.com/auth/spreadsheets.readonly'
        var authClient = null;
  
        if (authClient == null) {
          console.log('authentication failed');
          return;
        }
        callback(authClient);
      }
  </code></pre>