1

我已经尝试了几个小时,但我无法让它工作。我使用以下代码(VB)

Private Async Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Dim credential As UserCredential = Await GoogleWebAuthorizationBroker.AuthorizeAsync(New ClientSecrets With {.ClientId = "my key", .ClientSecret = "my secret"}, New String() {BooksService.Scope.Books}, "user", CancellationToken.None, New FileDataStore("Books.ListMyLibrary"))
        Dim service As New BooksService(New BaseClientService.Initializer With {.HttpClientInitializer = credential, .ApplicationName = "LibraryX"})

        'Dim bookselve As Bookshelves = Await service.Mylibrary.Bookshelves.List.ExecuteAsync
        Dim mm = service.Volumes.Get("9780330441230")

    End Sub

它没有给我关于这本书的信息(骆驼俱乐部,大卫巴尔达奇)

有人可以帮助我吗?

问候,史蒂文

20131106

我做了一些改变:

Private Async Sub Form1_Load(sender As Object, e As EventArgs) 处理 MyBase.Load

    Dim credential As UserCredential = Await GoogleWebAuthorizationBroker.AuthorizeAsync(New ClientSecrets With {.ClientId = "my key", .ClientSecret = "my secret"},
                                                                                         New String() {BooksService.Scope.Books}, "user", CancellationToken.None, New FileDataStore("Books.ListMyLibrary"))
    Dim service As New BooksService(New BaseClientService.Initializer With {.HttpClientInitializer = credential, .ApplicationName = "LibraryX"})

    'Dim bookselve As Bookshelves = Await service.Mylibrary.Bookshelves.List.ExecuteAsync
    Try
        rslt = Await service.Volumes.Get("9780330441230").ExecuteAsync
        Dim y As Integer = 0
    Catch gaex As Google.GoogleApiException
        ErrorMessageTextBox.Text = gaex.Message
    Catch ex As AggregateException
        ErrorMessageTextBox.Text = ex.Message
    End Try


End Sub

但是请求的结果是:

enter code hereGoogle.Apis.Requests.RequestError 找不到卷 ID。[404] 错误 [ 消息 [找不到卷 ID。] 位置 [ - ] 原因 [未找到] 域 [全局] ]

知道 VolumeId 必须是什么才能从 Google 获取图书信息吗?

4

2 回答 2

1

知道了!您应该对 GetRequest 对象使用 Execute 或 ExecuteAsync 方法。所以你的最后一行代码应该是这样的:

Dim mm = Await service.Volumes.Get("9780330441230").ExecuteAsync()

于 2013-11-05T15:22:37.520 回答
0

我使用 Google API Explorer 并在 books.volumes.list 方法中运行以下查询,q=intitle:"The Camel Club";inauthoer:David Baldacci

您可以在以下链接中找到它https://developers.google.com/apis-explorer/#p/books/v1/books.volumes.list?q=intitle%253A%2522The+Camel+Club%2522%253Binauthor %253A+大卫+巴尔达奇&_h=13&

我不是这个 API 的专家,但我在https://developers.google.com/books/docs/v1/using#PerformingSearch中找到了所有必需的信息。我很确定您可以优化查询,但这是一个很好的起点。

更新(添加 .NET 代码):
使用 Google API 资源管理器可用的每个操作也可使用 .NET 客户端库,如下所示:

var service = new BooksService(new BaseClientService.Initializer()
    {
        // HttpClientInitializer = credential,
        ApplicationName = "Books API Sample",
    });
var volumes = await service.Volumes.List(
      "intitle:\"The Camel Club\";inauthor: David Baldacci").ExecuteAsync();
foreach (var item in volumes.Items)
{
    Console.WriteLine(item.VolumeInfo.Title);
}

请注意,在这种情况下我们不需要 UserCredential,因为我们不查询用户的具体数据。如果要查询 Mylibrary,则应使用 UserCredential 和经过身份验证的请求。

于 2013-11-07T13:56:26.283 回答