未与我共享的文件夹列表,Google Drive API

时间:2017-11-06 12:57:56

标签: vb.net google-drive-api

在我的应用程序中,我想列出驱动器中存在的所有文件夹,但我不知道该怎么做。我想在" My Drive"中列出文件夹。不在"与我分享"。

这是我的代码:

 Dim fold = Service.Files.List()
       fold.Q = "mimeType = 'application/vnd.google-apps.folder'  and trashed = false and 'me' in owners "

但我有一个例外:Invalid Query [400]

1 个答案:

答案 0 :(得分:1)

您可以参考此here

此外,using Google.Apis.Auth.OAuth2; using Google.Apis.Drive.v3; using Google.Apis.Drive.v3.Data; using Google.Apis.Services; using Google.Apis.Util.Store; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace DriveQuickstart { class Program { // If modifying these scopes, delete your previously saved credentials // at ~/.credentials/drive-dotnet-quickstart.json static string[] Scopes = { DriveService.Scope.DriveReadonly }; static string ApplicationName = "Drive API .NET Quickstart"; static void Main(string[] args) { UserCredential credential; using (var stream = new FileStream("client_secret.json", FileMode.Open, FileAccess.Read)) { string credPath = System.Environment.GetFolderPath( System.Environment.SpecialFolder.Personal); credPath = Path.Combine(credPath, ".credentials/drive-dotnet-quickstart.json"); credential = GoogleWebAuthorizationBroker.AuthorizeAsync( GoogleClientSecrets.Load(stream).Secrets, Scopes, "user", CancellationToken.None, new FileDataStore(credPath, true)).Result; Console.WriteLine("Credential file saved to: " + credPath); } // Create Drive API service. var service = new DriveService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = ApplicationName, }); // Define parameters of request. FilesResource.ListRequest listRequest = service.Files.List(); listRequest.PageSize = 10; listRequest.Fields = "nextPageToken, files(id, name)"; // List files. IList<Google.Apis.Drive.v3.Data.File> files = listRequest.Execute() .Files; Console.WriteLine("Files:"); if (files != null && files.Count > 0) { foreach (var file in files) { Console.WriteLine("{0} ({1})", file.Name, file.Id); } } else { Console.WriteLine("No files found."); } Console.Read(); } } } 已设置为 false 作为默认值。从这里开始,您可以设置是否要在结果中包含团队驱动器。

尝试快速入门中的代码。

<select class="form-control" id="selet-city" required >
<option selected disabled>Please select a City</option>
<option vlaue="dsfsdfsd">bangalore</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>

关于您的错误,我认为您正在尝试使用特定于两个不同版本的搜索参数documentationDrive v3 API

有关详细信息,请参阅此Drive v2 API