Google Drive listFiles() Error - Using Velo Pacakge

TypeError: (0 , r.listFiles) is not a function

First I did in backend custom *.jsw but I didn’t work so I put it on the frontend page.

My code is same with Example,

import { listFiles } from '@velo/google-drive-integration-backend'
  
const query = 'mimeType = "image/png" or mimeType = "image/jpeg"';

// Returns the name and webViewLink
const fields = 'files(name, webViewLink)';

listFiles(query, fields)
  .then((data) => {
    if (data.files.length > 0) {
      const image = data.files[0];
      const name = image.name;
      const viewLink = image.webViewLink;
    }
  })
  .catch((error) => {
    console.log(error);
  });

Please Help…!



‘Wix Secrets Manager’

Hello! As per the readme for the package, this code is meant to be run in a backend file. This will not work from your page code, hence your current “is not a function” error.

What error did you receive when testing in the backend?

Also, it appears you have pasted private information from the secrets manage in your screenshot. If this token is not meant to be public, please delete it to protect yourself.

Thank you for reply

I wanted to know if Token was written in the correct format

If run in a backend file

Frontpage code,

import getDriveFolder from 'backend/googledrives';

const query = 'mimeType = "image/png" or mimeType = "image/jpeg"';
const fields = 'files(name, webViewLink)';
getDriveFolder(query , fields);

In ‘backend/googledrives’,

import { listFiles } from '@velo/google-drive-integration-backend'

export async function getDriveFolder(query , fields) {

   listFiles(query, fields).then((data) => {
    if (data.files.length > 0) {
      const image = data.files[0];
      const name = image.name;
      const viewLink = image.webViewLink;
    }
  })
  .catch((error) => {
    console.log(error);
  });

}

II have not worked with this package yet, but there are a few things going on with your code that you can explore to start.

In the frontend code…the backend function import should have braces like below. See importing web modules for more information

import {  getDriveFolder }  from'backend/googledrives';

In your backend file you have a function that is async, but you never use await. Here is some reading on promises.

Finally, another potential issue here is that nothing is being returned from your backend function.

Also web modules always return a promise which you will need to handle in the frontend code when you call it, see the first link about working with web modules for some simple examples.

Oh my god… what a shame… Thanks…!