Skip to content

Instantly share code, notes, and snippets.

@Musinux
Created January 17, 2018 00:00
Show Gist options
  • Save Musinux/9945da1a2afd284cef5ec0377f4b2460 to your computer and use it in GitHub Desktop.
Save Musinux/9945da1a2afd284cef5ec0377f4b2460 to your computer and use it in GitHub Desktop.
nodejs drive api v3 fetch children files from folder
const GoogleAuth = require('google-auth-library')
const OAuth2Client = GoogleAuth.OAuth2Client
const google = require('googleapis')
const clientId = '<YOUR_CLIENT_ID>'
const clientSecret = '<YOUR_CLIENT_SECRET>'
const redirectUri = '<Your URI Callback>'
const oauth2Client = new OAuth2Client(clientId, clientSecret, redirectUri)
// your oauth method, see documentation
const drive = google.drive({ version: 'v3', auth: oauth2Client })
/**
From now on, if you want to get the list of children, you must use a query string, in the form of
"'IDofYourFolder in' parents" where "in parents" indicates that Drive should look into IDofYouFolder
**/
drive.files.list({
q: `'${googleFolderId}' in parents`
}, (err, data) => {
if (err) throw err
console.log('your files', data)
})
@Musinux
Copy link
Author

Musinux commented Apr 5, 2021

@Calvin087 it's named Promises, so you can look here and there for some explanations and examples. If you need some links to learn node.js, go to my own list on github you may find some interesting information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment