Directly Using Access Token by googleapis for Node.js


This sample script is for directly using the refreshed access token by googleapis for Node.js. When oauth2Client.refreshAccessToken((err, tokens) => {}); is used to retrieve the refreshed access token, the following error occurs.

DeprecationWarning: The refreshAccess Token method has been deprecated, and will be removed in the 3.0 release of goo gle-auth-library. Please use the getRequestHeaders method instead.

It is required to use getRequestHeaders(). But I couldn’t find the sample script using getRequestHeaders(). So I created this sample script. If this was useful for you, I’m glad.

function listFiles(auth) {
  const request = require('request');

  .then((authorization) => {
    let qs = {
      "orderBy": "name",
      "pageSize": 5,
      "q": "mimeType='application/'",
      "fields": "files(id,name)",
    let options = {
      url: "",
      qs: qs,
      method: "get",
      headers: authorization,
    request(options, (err, res, result) => {
      if (err) {
  • In this sample script, listFiles(auth) in the quickstart script is used. When you use the quickstart script, please replace listFiles(auth) to the above script.