使用Google Books API [英] Using Google Books API

查看:103
本文介绍了使用Google Books API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Google Books API时遇到问题

I'm having trouble using the Google Books API

我没有使用JSON的经验.

I am inexperienced in working with JSON.

我的表单:

<form action="action.php" method="POST">
<div class="form-group">
    <div class="campos">
        <label>
         Search
        </label>
        <input type="text" name="search"  style="margin-right: 10px; width:250px; float:left" class="input-field" placeholder="Title, Author..."  />    
        <button type="submit" id="search" class="btn btn-default">Search</button>
    </div>
</div>

我的动作:

$var1 = "https://www.googleapis.com/books/v1/volumes?q=";
$var2 = urlencode($_POST['search']);
$str = str_replace(" ", "+", $var2);
$page = $var1.$str;
header ("location:$page");
$data = file_get_contents($page);
$data = json_decode($page, true);

因此,运行此代码将向我返回一个包含以下内容的json文件:

So running this code is returned to me one json file containing something like:

{
 "kind": "books#volumes",
 "totalItems": 584,
 "items": [
  {
  "kind": "books#volume",
  "id": "NkHwo2hKW6YC",
  "etag": "FNozDEeE+zY",
  "selfLink": "https://www.googleapis.com/books/v1/volumes/NkHwo2hKW6YC",
  "volumeInfo": {
  "title": "viagem ao redor da lua",
  "authors": [
   "JULIO VERNE"
  ],
  "publisher": "Hemus",
  "description": "Description of book",
  "industryIdentifiers": [
   {
   "type": "ISBN_10",
   "identifier": "8528901882"
   },
   {
    "type": "ISBN_13",
    "identifier": "9788528901887"
   }
  ],
   "readingModes": {
   "text": false,
   "image": true
  },
  "pageCount": 192,
  "printType": "BOOK",
  "averageRating": 3.0,
  "ratingsCount": 4,
  "contentVersion": "1.1.1.0.preview.1",
  "imageLinks": {
  "smallThumbnail": "http://bks6.books.google.com.br/books?id=NkHwo2hKW6YC&printsec=frontcover&img=1&zoom=5&edge=curl&source=gbs_api",
   "thumbnail": "http://bks6.books.google.com.br/books?id=NkHwo2hKW6YC&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api"
    },
  "language": "pt",
  "previewLink": "http://books.google.com.br/books?id=NkHwo2hKW6YC&printsec=frontcover&dq=Julio+verne&hl=&cd=1&source=gbs_api",
  "infoLink": "http://books.google.com.br/books?id=NkHwo2hKW6YC&dq=Julio+verne&hl=&source=gbs_api",
  "canonicalVolumeLink": "http://books.google.com.br/books/about/viagem_ao_redor_da_lua.html?hl=&id=NkHwo2hKW6YC"
 },
 "saleInfo": {
  "country": "BR",
  "saleability": "NOT_FOR_SALE",
  "isEbook": false
 },
 "accessInfo": {
  "country": "BR",
  "viewability": "PARTIAL",
  "embeddable": true,
  "publicDomain": false,
  "textToSpeechPermission": "ALLOWED",
  "epub": {
    "isAvailable": false
  },
  "pdf": {
   "isAvailable": false
  },
  "webReaderLink": "http://books.google.com.br/books/reader?id=NkHwo2hKW6YC&hl=&printsec=frontcover&output=reader&source=gbs_api",
  "accessViewStatus": "SAMPLE",
  "quoteSharingAllowed": false
 },
  "searchInfo": {
  "textSnippet": "Em uma época que não se conhecia a tecnologia, Verne consegue prever em forma de aventura, uma viagem pelo espaço até a Lua."
 }
 },
 ]  
}

我需要通过php显示一些此类信息.

I need to show some of this information by php.

推荐答案

请您检索JSON信息,这是最困难的部分.

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

为了通过php打印数据,请尝试以下操作;

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

这篇关于使用Google Books API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆