question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: Cannot read property 'data' of undefined on the sample code....

See original GitHub issue

Trying to run the sample code for the drive list stuff and am getting this error:

TypeError: Cannot read property 'data' of undefined at runSample (c:\Users\Konstantin\Desktop\USN\JS\newCode.js:15:19) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7)

Environment details

  • OS: Windows 10
  • Node.js version: 8.11.4
  • npm version: 6.4.1
  • googleapis version: 33.0.0

Steps to reproduce

  1. Run the Drive list sample code…

Bonus question: How can I create a token to use so that I don’t have to login each time the script is run?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:16 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
TheCreatorzOnecommented, Sep 14, 2018

Sure thing! 😃 I just have it inside VS Code and press the run button tbh… But here is the script:

'use strict';

const {google} = require('googleapis');
const sampleClient = require('./sampleclient');

const drive = google.drive({
  version: 'v3',
  auth: sampleClient.oAuth2Client
});

async function runSample (query) {
  const params = { 
      pageSize: 3,
      fields: "files(id, name, parents, size)"
    };
  params.q = query;
  const res = await drive.files.list(params);
  console.log(res.data);
  return res.data;
}

if (module === require.main) {
  const scopes = ['https://www.googleapis.com/auth/drive'];
  sampleClient.authenticate(scopes)
    .then(c => runSample())
    .catch(console.error);
}

module.exports = {
  runSample,
  client: sampleClient.oAuth2Client
};

It gets executed with node newCode.js

1reaction
TheCreatorzOnecommented, Sep 14, 2018

Ahhhh. That’s a pretty old version of googleapis 😃 Can you please upgrade to 33, and remove the dependency on google-auth-library?

Yeah, just did 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot Read Property of Undefined in JavaScript - Rollbar
TypeError: Cannot read property of undefined occurs when a property is read or a function is called on an undefined variable.
Read more >
TypeError: Cannot read property 'data' of undefined - can't ...
javascript - TypeError: Cannot read property 'data' of undefined - can't access Object "props" beyond certain level in Reactjs - Stack Overflow ...
Read more >
TypeError: Cannot read property 'data' of undefined
[0] (node:24430) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async ...
Read more >
How to Prevent the Error: Cannot Read Property '0' of Undefined
A guide on how to prevent the error "cannot Read Property '0' of Undefined", covering techniques such as try, catch, using const over...
Read more >
Uncaught TypeError: Cannot read property of undefined In
In the above code, when you get undefined error , you need to make sure that whichever variables throws undefined error, is assigned...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found