Using Google Books API

前端 未结 2 1812
刺人心
刺人心 2021-01-07 14:36

I\'m having trouble using the Google Books API

I am inexperienced in working with JSON.

My form:

相关标签:
2条回答
  • 2021-01-07 14:51

    Take a look at the Google Books API client library for PHP https://developers.google.com/books/docs/v1/libraries (They have some examples.) What you're trying to do is not going to work for at least two reasons:

    1. You have to authenticate to the API with your API Key.
    2. header("Location: $page"); redirects; it doesn't grab the page contents.

    Edit: The authenticating part is not true if you don't need to access or create your own "bookshelves." So you could try:

    $data = file_get_contents($page);
    $data = json_decode($data, true);
    $item = $data->items;
    
    0 讨论(0)
  • 2021-01-07 14:52

    Well you ale retrieving the JSON info so that's the hard part.

    In order to print the data via php try something like the following;

    $page = file_get_contents($page);
    
    $data = json_decode($page, true);
    
    echo "Title = " . $data['items'][0]['volumeInfo']['title'];
    echo "Authors = " . @implode(",", $data['items'][0]['volumeInfo']['authors']);    
    echo "Pagecount = " . $data['items'][0]['volumeInfo']['pageCount'];
    
    0 讨论(0)
提交回复
热议问题