0
votes

I have create a folders using google drive API on google drive and able to search folders and files created by API App. Inside this folder i created a folder and file manually on google drive. Now i can not able to find the file or folder that i created manually using driveService.Files.List() method. There is any way to access manually create file or folder by google drive API. The file search code is

var request = service.Files.List();
request.Q = "mimeType='application/vnd.google-apps.folder' and trashed=false";
request.Spaces = "drive";
var result = request.Execute();
foreach (var file in result.Files)
{
    string fileid = file.Id;
    string filename = file.Name;
}
2

2 Answers

1
votes

Solved by changing the app permission requests scope from "DriveService.Scope.DriveFile" to "DriveService.Scope.Drive"

private static readonly IAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
{
    ClientSecrets = new ClientSecrets
    {
        ClientId = Your_GoogleAPI_ClientId,
        ClientSecret = Your_GoogleAPI_ClientSecret
    },
    Scopes = new[] { DriveService.Scope.Drive },
    DataStore = new FileDataStore(Your_GoogleApi_Credential_File_Path)
});
0
votes

I would do it like this:

 function findMyFolder() {
        var folders = DriveApp.searchFolders(
            'mimeType="application/vnd.google-apps.folder" and trashed=false');
        while (folders.hasNext()) {
            var folder = folders.next();
            Logger.log("Folder ID:  " + folder.getId() + "  Folder Name:  " + folder.getName());
        }
    }

Files and Folders are different. You were searching Files for a Folder. I also switched around the quotes, but that's just a personal preference.