Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access Google Drive API Returns Empty File List

I'm testing out the Google Drive API. The test script does the HTTP GET to access the Files->List API but somehow I always get an empty list in items. I have hundreds of files in my google drive so the result is unexpected. The HTTP response is shown below.

    {
     "kind": "drive#fileList",
     "etag": "\"VEU5fga3uYlZRf0pG-N1kS4iWP4/Kxo5eGvPKynWfroe9v5L5T43-n0\"",
     "selfLink": "https://www.googleapis.com/drive/v2/files?maxResults=5",
     "items": []
    }
like image 319
kvzrock Avatar asked Oct 02 '12 20:10

kvzrock


People also ask

Why is my Google Drive not showing all files?

Google Drive users on both Android and iOS need to make sure to update the app, otherwise, the old version of the app may not work properly. So, Google Drive not showing all files error might be due to a bug in the app. Please go to the application center to check if Google Drive needs upgrading.

How do I get a list of files in Google Drive?

Goto the same Google Sheets File and refresh the page. Then you will get the "List Files/Folders" menu, click on it, and select the "List All Files and Folders" item.

Can Google Drive files disappear?

Files stored in Google Drive can “go missing” when they become “orphaned”. This is when the file exists but the parent folders it was located in are deleted. For example, this can occur if you create a file in a folder owned by someone else and that folder is deleted.


2 Answers

To allow service account to access the files in my own Google Drive, I have to give permission to the email address of the service account. Once the permissions are setup correctly, the list gets populated with the files that the service account is allowed to access.

like image 152
kvzrock Avatar answered Sep 20 '22 15:09

kvzrock


This usually means you've authenticated with a scope that doesn't give you permission to see those files.

For example, the scope https://www.googleapis.com/auth/drive.file only provides access to files created or opened by the app. You won't be able to access files created in the Google Drive interface or by other apps.

If you want to access all the files, you'll have to use another scope. https://www.googleapis.com/auth/drive, for example, gives you full, permissive scope to access all of a user's files.

You can find information about the available scopes here. Use it to pick the right scope for your app.

like image 23
Tiago Avatar answered Sep 22 '22 15:09

Tiago