如何使用.NET Google Drive API执行查询?

时间:2013-05-14 21:14:11

标签: c# google-drive-api

我正在使用C#API V2 for Google Drive,我似乎找不到FilesResource.ListRequest.Fetch()方法......我看到FilesResource.ListRequest接口与之前描述的略有不同谷歌驱动器文档,所以我猜它已经做了一些改变,但没有反映在网络文档中。有人知道我现在应该怎么执行查询吗?

这就是我想要运行的内容:

public void SomeMethod(Settings settings)
{
    var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description, settings.ApiKey, settings.ApiSecret);
    var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, AuthProvider);
    _driveService = new Google.Apis.Drive.v2.DriveService(new BaseClientService.Initializer {Authenticator = auth});

    var request = _driveService.Files.List();
    request.Q = "mimeType='application/vnd.google-apps.folder' and trashed=false";

    request.Fetch() // <-- This method does not exist! :/
}

提前致谢!

3 个答案:

答案 0 :(得分:2)

我刚刚使用最新版本的库尝试了您的代码,并且它正确构建。您使用的是最新版本的库吗?

FilesResource.ListRequest扩展Google.Apis.Requests.ClientServiceRequest<Google.Apis.Drive.v2.Data.FileList>,定义Fetch()

https://code.google.com/p/google-api-dotnet-client/source/browse/Src/GoogleApis/Apis/Requests/ClientServiceRequest.cs#197

答案 1 :(得分:2)

使用Execute()方法代替Fetch()

request.Execute()

答案 2 :(得分:0)

目前的方法似乎是ExecuteAsync

var request = _driveService.Files.List();
request.Q = "mimeType='application/vnd.google-apps.folder' and trashed=false";

var result = await request.ExecuteAsync()

我不确定这是否仅适用于Windows应用商店和Windows Phone 8.1应用,或者Execute方法是否已被删除。