Search for details of a book with Google Books API in PHP

6

I'm using Google Books API to get the details of a book:

And to get the details of a book by searching by name, I'm using the following example provided by they , in this case the file simple-query.php within the examples folder.

What happens is that I can only do the search by author of books when calling this function:

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

How can I search by book name? I can not find any reference to doing the search by book name.

As I could not do it for the above mode, I found an example on the internet, but the search is done by the URL

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

If I use this solution through the URL, how can I get the result through the code and be saved inside a variable / array?

    
asked by anonymous 12.01.2015 / 10:59

3 answers

2

You can read the data by JSON and manipulate it as you see fit:

<?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']);    
?>

Here is an example to get the Title and Authors of the book.

    
12.01.2015 / 12:11
1

In the Performing Search section, it is said that you can specify the book name ( or part of it) using the intitle parameter. For example:

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

Answer:

{
 "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
   }
  }
 ]
}
    
12.01.2015 / 12:29
0

Try using this code:

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
    
21.11.2015 / 20:45