Problems searching for file via Google Drive api

Asked

Viewed 81 times

0

I’m trying to return the file id from google drive based on the following example: Search for files and folders

code :

function searchFiles (auth) {
    const drive = google.drive({version: 'v3', auth});
    var pageToken = null;
    // Using the NPM module 'async'
    async.doWhilst(function (callback) {
        drive.files.list({
            q: "mimeType='image/jpeg'",
            fields: 'nextPageToken, files(id, name)',
            spaces: 'drive',
            pageToken: pageToken
         },function (err, res) {
            if (err) {
                // Handle error
                console.error(err);
                callback(err)
            } else {
                res.files.forEach(function (file) {
                    console.log('Found file: ', file.name, file.id);
                });
                pageToken = res.nextPageToken;
                callback();
            }
           });
    }, function () {
        return !!pageToken;
    }, function (err) {
        if (err) {
            // Handle error
            console.error(err);
        } else {
             // All pages fetched
        }
    })
}

Error:

(node:8136) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'forEach' of undefined
at C:\Users\Programador\Desktop\apiGDrive\gdrive-node\searchFiles.js:116:19
at createAPIRequestAsync.then.r (C:\Users\Programador\Desktop\apiGDrive\node_modules\googleapis-common\build\src\apirequest.js:48:53)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:8136) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:8136) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
  • of the one console.log(res);, within the function (err, res) { and see what comes back

  • @Douglasteles doesn’t show up, I’ve tried it..

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.