6

Estou a usar a API do Google books para ir buscar os detalhes de um livro:

E para ir buscar os detalhes de um livro, ao pesquisar pelo nome, estou a usar o seguinte exemplo fornecido por eles, deste caso o ficheiro simple-query.php dentro da pasta examples.

O que acontece é que só consigo fazer a pesquisa por autor de livros ao chamar esta função:

$results = $service->volumes->listVolumes('Catarina Coelho', $optParams);

Como posso fazer a pesquisa pelo nome do livro? Não encontro nenhuma referência a fazer a pesquisa pelo nome do livro.

Como não consegui fazer pelo modo de cima, encontrei um exemplo na internet, mas a pesquisa é feita pelo o URL

https://www.googleapis.com/books/v1/volumes?q=Memoria+historia+da+provincia+de+Santa+Catharina

Se usar esta solução pela URL, como posso ir buscar o resultado pelo código e ficar guardado dentro de uma variável/array?

3 Respostas 3

2

Podes ler os dados por JSON e assim manipular da forma que entenderes:

<?php
$page = file_get_contents("https://www.googleapis.com/books/v1/volumes?q=Memoria+historia+da+provincia+de+Santa+Catharina");

$data = json_decode($page, true);

echo "Title = " . $data['items'][0]['volumeInfo']['title'];
echo "<br/>Authors = " . @implode(",", $data['items'][0]['volumeInfo']['authors']);    
?>

Aqui esta um exemplo para ires buscar o Title e Authors do livro.

1

Na seção Performing Search, diz-se que é possível especificar o nome do livro (ou parte dele) usando o parâmetro intitle. Por exemplo:

http https://www.googleapis.com/books/v1/volumes?q=intitle:Cem+Anos+de+Solidao

Resposta:

{
 "kind": "books#volumes",
 "totalItems": 17,
 "items": [
  {
   "kind": "books#volume",
   "id": "iPxztgAACAAJ",
   "etag": "2jx8ktgU3G8",
   "selfLink": "https://www.googleapis.com/books/v1/volumes/iPxztgAACAAJ",
   "volumeInfo": {
    "title": "Cem anos de solidão",
    "authors": [
     "Gabriel García Márquez"
    ],
    "publishedDate": "1973",
    "industryIdentifiers": [
     {
      "type": "OTHER",
      "identifier": "OCLC:6522501"
     }
    ],
    "readingModes": {
     "text": false,
     "image": false
    },
    "pageCount": 364,
    "printType": "BOOK",
    "contentVersion": "preview-1.0.0",
    "language": "en",
    "previewLink": "http://books.google.com.br/books?id=iPxztgAACAAJ&dq=intitle:Cem+Anos+de+Solidao&hl=&cd=1&source=gbs_api",
    "infoLink": "http://books.google.com.br/books?id=iPxztgAACAAJ&dq=intitle:Cem+Anos+de+Solidao&hl=&source=gbs_api",
    "canonicalVolumeLink": "http://books.google.com.br/books/about/Cem_anos_de_solid%C3%A3o.html?hl=&id=iPxztgAACAAJ"
   },
   "saleInfo": {
    "country": "BR",
    "saleability": "NOT_FOR_SALE",
    "isEbook": false
   },
   "accessInfo": {
    "country": "BR",
    "viewability": "NO_PAGES",
    "embeddable": false,
    "publicDomain": false,
    "textToSpeechPermission": "ALLOWED",
    "epub": {
     "isAvailable": false
    },
    "pdf": {
     "isAvailable": false
    },
    "webReaderLink": "http://books.google.com.br/books/reader?id=iPxztgAACAAJ&hl=&printsec=frontcover&output=reader&source=gbs_api",
    "accessViewStatus": "NONE",
    "quoteSharingAllowed": false
   }
  }
 ]
}
0

Tente usar esse código:

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    'Step 1:- google API url responsible for returning the book detail in JASON format
    Const GOOGLEAPIURL As String = "https://www.googleapis.com/books/v1/volumes?q=&#8221;"

    If txtISBN.Text <> String.Empty Then
        Dim requestURL As String

        'Step 2:- Reformed the URL to target particular ISBN number
        requestURL = GOOGLEAPIURL + txtISBN.Text() + "+isbn"

        'Step 3: created Http webrequest for URL
        Dim wr As HttpWebRequest = HttpWebRequest.Create(requestURL)
        'Step4 : get the response of web request in http web response object
        Dim resp As HttpWebResponse = wr.GetResponse()

        'Step 5: passes the response stream in stream reader
        Dim sreader As New StreamReader(resp.GetResponseStream())
        'Step 6: parsing the reader(which is in Jason format) using JASON.NET

        Dim rss = JObject.Parse(sreader.ReadToEnd())

        'Step 7: if object find the fetch the detail

        If rss Is Nothing = False AndAlso rss.Count > 0 Then
            lblBookName.Text = rss.Item("items")(0).Item("volumeInfo").Item("title").ToString()
            lblAuthor.Text = rss.Item("items")(0).Item("volumeInfo").Item("authors").ToString().Replace("[", "").Replace("]", "").ToString()
            lblPublisher.Text = rss.Item("items")(0).Item("volumeInfo").Item("publisher").ToString()
        Else
            lblMessage.Text = "Sorry ISBN Number not found, Please try different number."
        End If
    Else
        lblMessage.Text = "Please enter the ISBN number"
    End If
End Sub
1
  • 3
    A linguagem do OP é php, e esse código sugerio em VB.
    – user28595
    21/11/2015 às 20:18

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .