4

i want to check if a folder belongs to shared drive or not . I implement this code but it return Error 400 invalid value on Query.

            var request = service.Files.List();
            var query = "id='" + driveFileId + "'";
            request.IncludeTeamDriveItems = true;
            request.SupportsTeamDrives = true;
            request.Q = query;

            request.Fields = "nextPageToken, files(id, name,parents,mimeType)";

            request.PageToken = pageToken;

            var result =request.Execute();
Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
ba7russ
  • 68
  • 4

1 Answers1

3

The following code will look for a folder on my drive account called kintting.

It will then loop though all the results (there could be more then one) check the two parameters one of them should tell you if its part of team.

var request = service.Files.List();
request.Q = "name='knitting' and mimeType='application/vnd.google-apps.folder'";
request.Fields = "*";
var result = await request.ExecuteAsync();

foreach (var file in result.Files)
     {
      // check file.DriveId or file.TeamDriveId

      }

If you have the id of the folder in question. from say a previous search. you can get it directly using

 var request = service.Files.Get(fileId);
 request.Fields = "*";
 var result = await request.ExecuteAsync();
Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • Thnks for the answer but you are looping throughh the result for my case i have 17400 Files and this take to much time i want to optimize the time by searching the id through the Query. Is this possible? – ba7russ Jan 10 '20 at 09:25
  • Do you see the q paramater? this is for searching, its only looking for folders. hence the **mimetype**. Its also searching for the folder by **name**. It wouldn't be looping though 17400 files unless you have 17400 folders with the same name that you want to search though. This is really your only option unless you have the folder id from a previous call and then you can just use files.get. – Linda Lawton - DaImTo Jan 10 '20 at 09:35
  • 1
    Well... That sucks so hard! If you, indeed, have thousands of folders, and you indeed have the IDs from previous requests (for example: from the change endpoint), why in the hell would you perform thousands of requests? And why the heck would you request folders by name if you already have the ID? – Anibal E. Alvarez Sifontes Nov 08 '22 at 23:47
  • its a free api Unforuantatly this is how it works. Google is saving them traffic by only returning the data they are sure you will need. If you want more you need to ask for it. – Linda Lawton - DaImTo Nov 09 '22 at 06:58