Home > database >  How do I search Google Drive API by date?
How do I search Google Drive API by date?

Time:10-12

I am using Google Drive V3 API to manipulate files in a folder.

What I am currently doing to list all my files is like so:

const data = await drive.files.list({ q: `'${folderId}' in parents` });
console.log(data.files);

So basically I'm using a service account to query a folder for all its files. I'd also like to query for date. Something like createdTime < ${date}.

Reading through a few posts on this site and the documentation, there doesn't seem to be such a feature to do so. I can see that there is the option to use modifiedTime, however when I try to use it, everything just freezes up and the script run indefinitely.

Does anyone have any ideas as to how I can query this?

Edit 21/10/12 11:08

So I tried doing the following per Taneike's suggestion:

console.log('1') //this logs in the console
const data = drive.files.list({
    q: `'${folderId}' in parents and createdTime > 2012-06-04T12:00:00-08:00`,
});
//unreachable code below
console.log('2') //this doesn't log
console.log(data) //this doesn't log

So basically my script will run indefinitely, and I have to manually end the script. drive.files.list won't return anything.

CodePudding user response:

I thought that createdTime < date can be used. And, when I saw your script, I noticed that there is a modification point. And, from your replying of So at the moment, I am able to retrieve all the files in 'Folder A' by using {q: ''${folderID}' in parents'}. What I would like to do is also query it by date. So for example, {q: ''${folderId}' in parents and createdTime < ${date}'}. –, I thought that there might be also a modification point.

When the above points are reflected in your script, it becomes as follows.

Modified script:

const data = await drive.files.list({q: `'${folderId}' in parents and createdTime < '${date}'`}).catch((err) => console.log(err.errors));
console.log(data.data);
  • In this case, please set the value of date like 2012-06-04T12:00:00-08:00 as RFC3339 format.

References:

  • Related