Click here to Skip to main content
15,885,847 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have implemented a Google Drive API Tool and i try to list all files which are held in Google Drive. But i only can see the files which i uploaded with my API Tool. When i upload a file with the Google Drive Web then i can see it only in the Web interface, but not in my API Tool. I thought with the API Tool i have full access to my personal Google Drive. Why can't i see all files?

What I have tried:

When i upload a file with the Google Drive Web then i can see it only in the Web interface, but not in my API Tool.
C#
public static Dictionary<string,string> GetFiles(bool gelöschteanzeigen)
        {
            Dictionary<string, string> listdateien = new Dictionary<string, string>();

            string pageToken = null;
            do
            {
                var request = service.Files.List();

                if (gelöschteanzeigen)
                    request.Q = "trashed = true and '" + RootId + "'" + " in parents";
                else
                    request.Q = "trashed = false and '" + RootId + "'" + " in parents";

                request.Spaces = "drive";
               request.Fields = "nextPageToken, files(id, name)";
                request.PageToken = pageToken;
                var result = request.Execute();
                foreach (var file in result.Files)
                {
                    listdateien.Add(file.Id, file.Name);
                }
                pageToken = result.NextPageToken;
            } while (pageToken != null);
            
            
            return listdateien;
        }
Posted
Updated 13-Sep-17 8:02am
v4
Comments
Richard MacCutchan 13-Sep-17 11:40am    
Ask Google, it's their API.

I have done a lot of work with the Google Drive API and have not experienced what you are mentioning. Their file/folder system works a bit different to most. Check that you are looking in the correct folder location.

Maybe this documentation will help: Search for Files  |  Drive REST API  |  Google Developers[^]
 
Share this answer
 
Comments
Member 11930819 13-Sep-17 13:33pm    
hey, thanks for your answer, but i already found the link and couldn't solve it on my own.

Here i wanna show you my method to get the Files from a folder by id:

[code moved into question]

I only get a List with the files, which i uploaded with the API.
Graeme_Grant 13-Sep-17 13:48pm    
Your code is not checking for more data, so you may only be seeing the first page of results. This may also be why. Documentation states:
Multiple corpora and Team Drives may be searched in a single query, though incomplete results may be returned if the combined corpus is too large. If the incompleteSearch field in the result is true, not all documents have been searched.

The example on the link provided above shows you how to get "all" the data.

Here is a link to the example on that page: Search for Files  |  Drive REST API  |  Google Developers[^]
Member 11930819 13-Sep-17 14:00pm    
hm, i have updated my code, it looks now very similar to your suggestion. But i get the same list as before.
Graeme_Grant 13-Sep-17 14:08pm    
I have run a test a few minutes ago:
1. Add a new File, Delete a file, rename a folder, using: Google Drive web interface[^]
2. Use API to read folders and file and everything looked just as expected.

The problem may be in your query.
Member 11930819 13-Sep-17 14:23pm    
strange, i can't find a mistake there... maybe i can show you via skype?
It sounds to me like you are using service account authentication.

Remember that a service account is not you think of it as a dummy user. When you upload using a service account you are uploading to the google drive account owned by the service account. When you run file.list as the service account you are going to see the files uploaded to the service accounts Google drive account.

You are not going to see the files uploaded to the service accounts google drive account in your own web version of Google drive unless you have the service account share the files with you.

Linda
 
Share this answer
 
Comments
Member 11930819 15-Sep-17 12:18pm    
Well i can see all files in my own web version of Google drive, even those which i uploaded with the service account. But i can't list all files in my tool.

So, how can i share the service files and the "web files" that i don't work only in the "service field"?
Linda Lawton 15-Sep-17 12:39pm    
The service account cant list files it doesn't have access to have you granted it access to the files in your dive account that its not listing?

Note: Sharing a folder with a service account does not always grant it permissions to see all new files added to said folder.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900