Google Drive API does not work when trying to query files in My Drive, no exception thrown, just empty list while my drives actually contains files - google-drive-api

Was trying to use Google Drive API (Java) in my android project. I logged in successfully, and was able to use the list() method successfully, but the getFiles() method return a empty List whereas my google drive actually having more than 100 files. I couldn't find any answer regarding this.

Related

Failing to get a file in Google Apps Script using the Drive API

I have a google apps script (that I use in one of my spreadsheets). I'm used to calling the DriveApp service to handle files (list, create, move, etc), but I wanted to get the user that last modified a file. Looking it up in several places, I understood that the only way to achieve that is to import the Drive API SDK (the Advanced Drive Service) into the Google Apps script. I added it using the official documentation. So, here is where I'm stuck. To simplify, look at the code below:
console.log(DriveApp.getFileById('1eMIUTEmpvzN5a3kK6PWbK4W8RCkbNOSxxxxxxxxxxx').getName())
console.log(Drive.Files.get('1eMIUTEmpvzN5a3kK6PWbK4W8RCkbNOSxxxxxxxxxxx').title)
The first one shows my file name just fine.
The second one fails with:
GoogleJsonResponseException: API call to drive.files.get failed with
error: File not found: 1eMIUTEmpvzN5a3kK6PWbK4W8RCkbNOSxxxxxxxxxxx
(anonyme) # List Files.gs:2
Any ideas why it wouldn't work?
From your script and your error of File not found, I thought that in your situation, the file might be put in the shared Drive. If my understanding is correct, such error occurs. On the other hand, when DriveApp.getFileById is used, the file in the shared Drive can be retrieved. So in your situation, how about the following modification?
From:
console.log(Drive.Files.get('1eMIUTEmpvzN5a3kK6PWbK4W8RCkbNOSxxxxxxxxxxx').title)
To:
console.log(Drive.Files.get('1eMIUTEmpvzN5a3kK6PWbK4W8RCkbNOSxxxxxxxxxxx', {supportsAllDrives: true}).title)
Reference:
Files: get

Google Drive list API - Empty list

I am using google drive list api. For one G-Suite domain I get empty list. I tried in API explorer, same result.
Tried for another G-Suite domain, I get response as described in the documentation, works both in API explorer and my code.
What is it I am missing here?
The method Drives: list lists only the shared drives of a Google Drive user.
If the resulting list is empty, this means that there is no shared drive associated with the given account
To create a new shared drive, follow the corresponding instructions
After successfully creating a shared drive, it will show up in the results of Drives: list

How to get a list of drive files that are orphaned

I am trying to get a list of files in my drive that have been orphaned. I tried using the search term is:orphaned but I just get :
Invalid argument: q (line 56, file "Code")
Does anyone know the right search term for searching orphaned drive files in apps script?
It's currently not possible to list orphaned files using the Drive API or the DriveApp method in Apps Script.
You can find the list of available search queries and terms for the Drive API here. While there is a parents file query term, this is for finding files with parents of a specific ID as shown in the files resource documentation.
You can head to Google's Issue Tracker to file a Feature Request for this though, which will let Google know that this is a desired feature of the API.

How can I get a list of all activity on a file created in Google Drive?

In the "activity list" of my file stored on Google drive, I see a message "File flagged as containing restricted content". I would like to write a script that goes through the activity list of all files I own, and identifies if any other files have been flagged similarly.
Screenshot showing Google Drive Activity: File flagged as containing restricted content
I looked through the the File Class documentation for Google App Script (https://developers.google.com/apps-script/reference/drive/file ) and did not find anything that looked like it would get Activity details of a file object
I am open to suggestions for finding activity information using Google App Scripts, or other methods if available. Please provide some context if suggesting other methods as I am only familiar with Google App Scripts.

What is the Google Drive file parents limit

I'm using Google Drive as a storage and decided to put one file into multiple folders (~500) in my case. I called Google Drive v2 API PUT files method to update file parents. It returns me error 400.
Does anybody know what is the addParents and removeParents limitation?