Zend_Gdata_Books.xml 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.gdata.books">
  4. <title>Using the Book Search Data API</title>
  5. <para>
  6. The Google Book Search Data <acronym>API</acronym> allows client applications to view
  7. and update Book Search content in the form of Google Data <acronym>API</acronym> feeds.
  8. </para>
  9. <para>
  10. Your client application can use the Book Search Data <acronym>API</acronym> to issue
  11. full-text searches for books and to retrieve standard book information,
  12. ratings, and reviews. You can also access individual users'
  13. <ulink url="http://books.google.com/googlebooks/mylibrary/">library collections and
  14. public reviews</ulink>. Finally, your application can submit authenticated requests
  15. to enable users to create and modify library collections, ratings, labels,
  16. reviews, and other account-specific entities.
  17. </para>
  18. <para>
  19. For more information on the Book Search Data <acronym>API</acronym>, please refer to the official
  20. <ulink url="http://code.google.com/apis/books/gdata/developers_guide_php.html">PHP
  21. Developer's Guide</ulink> on code.google.com.
  22. </para>
  23. <sect2 id="zend.gdata.books.authentication">
  24. <title>Authenticating to the Book Search service</title>
  25. <para>
  26. You can access both public and private feeds using the Book Search
  27. Data <acronym>API</acronym>. Public feeds don't require any authentication, but they are
  28. read-only. If you want to modify user libraries, submit reviews or
  29. ratings, or add labels, then your client needs to authenticate before
  30. requesting private feeds. It can authenticate using either of two
  31. approaches: AuthSub proxy authentication or ClientLogin username/password
  32. authentication. Please refer to the <ulink
  33. url="http://code.google.com/apis/books/gdata/developers_guide_php.html#Authentication">
  34. Authentication section in the <acronym>PHP</acronym> Developer's Guide</ulink> for more detail.
  35. </para>
  36. </sect2>
  37. <sect2 id="zend.gdata.books.searching_for_books">
  38. <title>Searching for books</title>
  39. <para>
  40. The Book Search Data <acronym>API</acronym> provides a number of feeds that list collections of books.
  41. </para>
  42. <para>
  43. The most common action is to retrieve a list of books that match a
  44. search query. To do so you create a <code>VolumeQuery</code> object
  45. and pass it to the <code>Books::getVolumeFeed</code> method.
  46. </para>
  47. <para>
  48. For example, to perform a keyword query, with a filter on
  49. viewability to restrict the results to partial or full view books, use
  50. the <code>setMinViewability</code> and <code>setQuery</code> methods
  51. of the <code>VolumeQuery</code> object. The following code snippet prints
  52. the title and viewability of all volumes whose metadata or text matches
  53. the query term "domino":
  54. </para>
  55. <programlisting language="php"><![CDATA[
  56. $books = new Zend_Gdata_Books();
  57. $query = $books->newVolumeQuery();
  58. $query->setQuery('domino');
  59. $query->setMinViewability('partial_view');
  60. $feed = $books->getVolumeFeed($query);
  61. foreach ($feed as $entry) {
  62. echo $entry->getVolumeId();
  63. echo $entry->getTitle();
  64. echo $entry->getViewability();
  65. }
  66. ]]></programlisting>
  67. <para>
  68. The <code>Query</code> class, and subclasses like
  69. <code>VolumeQuery</code>, are responsible for constructing feed
  70. <acronym>URL</acronym>s. The VolumeQuery shown above constructs a <acronym>URL</acronym> equivalent to the
  71. following:
  72. </para>
  73. <programlisting language="php"><![CDATA[
  74. http://www.google.com/books/feeds/volumes?q=keyword&amp;min-viewability=partial
  75. ]]></programlisting>
  76. <para>
  77. Note: Since Book Search results are
  78. public, you can issue a Book Search query without authentication.
  79. </para>
  80. <para>
  81. Here are some of the most common <code>VolumeQuery</code>
  82. methods for setting search parameters:
  83. </para>
  84. <para>
  85. <code>setQuery:</code> Specifies a search
  86. query term. Book Search searches all book metadata and full text for
  87. books matching the term. Book metadata includes titles, keywords,
  88. descriptions, author names, and subjects.
  89. Note that any spaces, quotes or other punctuation in the parameter
  90. value must be <acronym>URL</acronym>-escaped. (Use a plus (<code>+</code>) for a space.)
  91. To search for an exact phrase, enclose the phrase in quotation marks.
  92. For example, to search for books matching the phrase "spy plane", set
  93. the <code>q</code> parameter to <code>%22spy+plane%22</code>.
  94. You can also use any of the <ulink url="http://books.google.com/advanced_book_search">
  95. advanced search operators</ulink> supported by Book Search. For example,
  96. <code>jane+austen+-inauthor:austen</code> returns matches that mention
  97. (but are not authored by) Jane Austen.
  98. </para>
  99. <para>
  100. <code>setStartIndex:</code> Specifies
  101. the index of the first matching result that should be included in the
  102. result set. This parameter uses a one-based index, meaning the first
  103. result is 1, the second result is 2 and so forth. This parameter works
  104. in conjunction with the max-results
  105. parameter to determine which results to return. For example, to
  106. request the third set of 10 results—results 21-30—set
  107. the <code>start-index</code> parameter to <code>21</code> and the
  108. max-results parameter to <code>10</code>.
  109. Note: This isn't a general cursoring
  110. mechanism. If you first send a query with
  111. <code>?start-index=1&amp;max-results=10</code> and then send another
  112. query with <code>?start-index=11&amp;max-results=10</code>, the
  113. service cannot guarantee that the results are equivalent to
  114. <code>?start-index=1&amp;max-results=20</code>, because insertions and
  115. deletions could have taken place in between the two queries.
  116. </para>
  117. <para>
  118. <code>setMaxResults:</code>
  119. Specifies the maximum number of results that should be included
  120. in the result set. This parameter works in conjunction with the
  121. start-index parameter to determine which
  122. results to return. The default value of this parameter is
  123. <code>10</code> and the maximum value is <code>20</code>.
  124. </para>
  125. <para>
  126. <code>setMinViewability:</code>
  127. Allows you to filter the results according to the books'
  128. <ulink url="http://code.google.com/apis/books/docs/dynamic-links.html#terminology">
  129. viewability status</ulink>.
  130. This parameter accepts one of three values: <code>'none'</code>
  131. (the default, returning all matching books regardless of
  132. viewability), <code>'partial_view'</code> (returning only books
  133. that the user can preview or view in their entirety), or
  134. <code>'full_view'</code> (returning only books that the user can
  135. view in their entirety).
  136. </para>
  137. <sect3 id="zend.gdata.books.partner_restrict">
  138. <title>Partner Co-Branded Search</title>
  139. <para>
  140. Google Book Search provides <ulink
  141. url="http://books.google.com/support/partner/bin/answer.py?hl=en&amp;answer=65113">
  142. Co-Branded Search</ulink>, which lets content partners provide full-text search of
  143. their books from their own websites.
  144. </para>
  145. <para>
  146. If you are a partner who wants to do Co-Branded Search using the
  147. Book Search Data <acronym>API</acronym>, you may do so by modifying the feed <acronym>URL</acronym> above to
  148. point to your Co-Branded Search implementation. If, for example, a
  149. Co-Branded Search is available at the following <acronym>URL</acronym>:
  150. </para>
  151. <programlisting language="php"><![CDATA[
  152. http://www.google.com/books/p/PARTNER_COBRAND_ID?q=ball
  153. ]]></programlisting>
  154. <para>
  155. then you can obtain the same results using the Book Search Data <acronym>API</acronym> at the
  156. following <acronym>URL</acronym>:
  157. </para>
  158. <programlisting language="php"><![CDATA[
  159. http://www.google.com/books/feeds/p/PARTNER_COBRAND_ID/volumes?q=ball+-soccer
  160. ]]></programlisting>
  161. <para>
  162. To specify an alternate <acronym>URL</acronym> when querying a volume feed, you can
  163. provide an extra parameter to <code>newVolumeQuery</code>
  164. </para>
  165. <programlisting language="php"><![CDATA[
  166. $query =
  167. $books->newVolumeQuery('http://www.google.com/books/p/PARTNER_COBRAND_ID');
  168. ]]></programlisting>
  169. <para>
  170. For additional information or support, visit our
  171. <ulink url="http://books.google.com/support/partner/">Partner help center</ulink>.
  172. </para>
  173. </sect3>
  174. </sect2>
  175. <sect2 id="zend.gdata.books.community_features">
  176. <title>Using community features</title>
  177. <sect3 id="zend.gdata.books.adding_ratings">
  178. <title>Adding a rating</title>
  179. <para>
  180. A user can add a rating to a book. Book Search uses a 1-5
  181. rating system in which 1 is the lowest rating. Users cannot
  182. update or delete ratings.
  183. </para>
  184. <para>
  185. To add a rating, add a <code>Rating</code> object to a
  186. <code>VolumeEntry</code> and post it to the annotation feed.
  187. In the example below, we start from an empty <code>VolumeEntry</code> object.
  188. </para>
  189. <programlisting language="php"><![CDATA[
  190. $entry = new Zend_Gdata_Books_VolumeEntry();
  191. $entry->setId(new Zend_Gdata_App_Extension_Id(VOLUME_ID));
  192. $entry->setRating(new Zend_Gdata_Extension_Rating(3, 1, 5, 1));
  193. $books->insertVolume($entry, Zend_Gdata_Books::MY_ANNOTATION_FEED_URI);
  194. ]]></programlisting>
  195. </sect3>
  196. <sect3 id="zend.gdata.books.reviews">
  197. <title>Reviews</title>
  198. <para>
  199. In addition to ratings, authenticated users can submit reviews or
  200. edit their reviews. For information on how to request previously
  201. submitted reviews, see <ulink
  202. url="#zend.gdata.books.retrieving_annotations">Retrieving annotations</ulink>.
  203. </para>
  204. <sect4 id="zend.gdata.books.adding_review">
  205. <title>Adding a review</title>
  206. <para>
  207. To add a review, add a <code>Review</code> object to a
  208. <code>VolumeEntry</code> and post it to the annotation
  209. feed. In the example below, we start from an existing
  210. <code>VolumeEntry</code> object.
  211. </para>
  212. <programlisting language="php"><![CDATA[
  213. $annotationUrl = $entry->getAnnotationLink()->href;
  214. $review = new Zend_Gdata_Books_Extension_Review();
  215. $review->setText("This book is amazing!");
  216. $entry->setReview($review);
  217. $books->insertVolume($entry, $annotationUrl);
  218. ]]></programlisting>
  219. </sect4>
  220. <sect4 id="zend.gdata.books.editing_review">
  221. <title>Editing a review</title>
  222. <para>
  223. To update an existing review, first you retrieve the
  224. review you want to update, then you modify it, and
  225. then you submit it to the annotation feed.
  226. </para>
  227. <programlisting language="php"><![CDATA[
  228. $entryUrl = $entry->getId()->getText();
  229. $review = new Zend_Gdata_Books_Extension_Review();
  230. $review->setText("This book is actually not that good!");
  231. $entry->setReview($review);
  232. $books->updateVolume($entry, $entryUrl);
  233. ]]></programlisting>
  234. </sect4>
  235. </sect3>
  236. <sect3 id="zend.gdata.books.labels">
  237. <title>Labels</title>
  238. <para>
  239. You can use the Book Search Data <acronym>API</acronym> to label volumes with
  240. keywords. A user can submit, retrieve and modify labels. See
  241. <ulink url="#zend.gdata.books.retrieving_annotations">Retrieving
  242. annotations</ulink> for how to read previously submitted labels.
  243. </para>
  244. <sect4 id="zend.gdata.books.submitting_labels">
  245. <title>Submitting a set of labels</title>
  246. <para>
  247. To submit labels, add a <code>Category</code> object
  248. with the scheme <constant>LABELS_SCHEME</constant> to a
  249. <code>VolumeEntry</code> and post it to the annotation feed.
  250. </para>
  251. <programlisting language="php"><![CDATA[
  252. $annotationUrl = $entry->getAnnotationLink()->href;
  253. $category = new Zend_Gdata_App_Extension_Category(
  254. 'rated',
  255. 'http://schemas.google.com/books/2008/labels');
  256. $entry->setCategory(array($category));
  257. $books->insertVolume($entry, Zend_Gdata_Books::MY_ANNOTATION_FEED_URI);
  258. ]]></programlisting>
  259. </sect4>
  260. </sect3>
  261. <sect3 id="zend.gdata.books.retrieving_annotations">
  262. <title>Retrieving annotations: reviews, ratings, and labels</title>
  263. <para>
  264. You can use the Book Search Data <acronym>API</acronym> to retrieve annotations
  265. submitted by a given user. Annotations include reviews, ratings, and
  266. labels. To retrieve any user's annotations, you can send an
  267. unauthenticated request that includes the user's user ID. To retrieve the
  268. authenticated user's annotations, use the value <code>me</code> as the user ID.
  269. </para>
  270. <programlisting language="php"><![CDATA[
  271. $feed = $books->getVolumeFeed(
  272. 'http://www.google.com/books/feeds/users/USER_ID/volumes');
  273. <i>(or)</i>
  274. $feed = $books->getUserAnnotationFeed();
  275. // print title(s) and rating value
  276. foreach ($feed as $entry) {
  277. foreach ($feed->getTitles() as $title) {
  278. echo $title;
  279. }
  280. if ($entry->getRating()) {
  281. echo 'Rating: ' . $entry->getRating()->getAverage();
  282. }
  283. }
  284. ]]></programlisting>
  285. <para>
  286. For a list of the supported query parameters, see the
  287. <ulink url="#zend.gdata.books.query_parameters">query parameters</ulink>
  288. section.
  289. </para>
  290. </sect3>
  291. <sect3 id="zend.gdata.books.deleting_annotations">
  292. <title>Deleting Annotations</title>
  293. <para>
  294. If you retrieved an annotation entry containing ratings,
  295. reviews, and/or labels, you can remove all annotations
  296. by calling <code>deleteVolume</code> on that entry.
  297. </para>
  298. <programlisting language="php"><![CDATA[
  299. $books->deleteVolume($entry);
  300. ]]></programlisting>
  301. </sect3>
  302. </sect2>
  303. <sect2 id="zend.gdata.books.sharing_with_my_library">
  304. <title>Book collections and My Library</title>
  305. <para>
  306. Google Book Search provides a number of user-specific
  307. book collections, each of which has its own feed.
  308. </para>
  309. <para>
  310. The most important collection is the user's My Library, which
  311. represents the books the user would like to remember, organize, and
  312. share with others. This is the collection the user sees when accessing
  313. his or her <ulink url="http://books.google.com/books?op=library">My Library
  314. page</ulink>.
  315. </para>
  316. <sect3 id="zend.gdata.books.retrieving_books_in_library">
  317. <title>Retrieving books in a user's library</title>
  318. <para>
  319. The following sections describe how to retrieve a list
  320. of books from a user's library, with or without query
  321. parameters.
  322. </para>
  323. <para>
  324. You can query a Book Search public feed without authentication.
  325. </para>
  326. <sect4 id="zend.gdata.books.retrieving_all_books_in_library">
  327. <title>Retrieving all books in a user's library</title>
  328. <para>
  329. To retrieve the user's books, send a query to the
  330. My Library feed. To get the library of the authenticated
  331. user, use <code>me</code> in place of <constant>USER_ID</constant>.
  332. </para>
  333. <programlisting language="php"><![CDATA[
  334. $feed = $books->getUserLibraryFeed();
  335. ]]></programlisting>
  336. <para>
  337. Note: The feed may not contain all of the user's books, because
  338. there's a default limit on the number of results returned. For
  339. more information, see the <code>max-results</code> query parameter in
  340. <ulink url="#zend.gdata.books.searching_for_books">Searching for books</ulink>.
  341. </para>
  342. </sect4>
  343. <sect4 id="zend.gdata.books.retrieving_books_in_library_with_query">
  344. <title>Searching for books in a user's library</title>
  345. <para>
  346. Just as you can <ulink
  347. url="#zend.gdata.books.searching_for_books">search across all books</ulink>,
  348. you can do a full-text search over just the books in a
  349. user's library. To do this, just set the appropriate
  350. paramters on the <code>VolumeQuery</code> object.
  351. </para>
  352. <para>
  353. For example, the following query returns all the books in
  354. your library that contain the word "bear":
  355. </para>
  356. <programlisting language="php"><![CDATA[
  357. $query = $books->newVolumeQuery(
  358. 'http://www.google.com/books/feeds/users' .
  359. '/USER_ID/collections/library/volumes');
  360. $query->setQuery('bear');
  361. $feed = $books->getVolumeFeed($query);
  362. ]]></programlisting>
  363. <para>
  364. For a list of the supported query parameters, see the
  365. <ulink url="#zend.gdata.books.query_pParameters">query parameters</ulink>
  366. section. In addition, you can search for books that have been
  367. <ulink url="#zend.gdata.books.labels">labeled by the user</ulink>:
  368. </para>
  369. <programlisting language="php"><![CDATA[
  370. $query = $books->newVolumeQuery(
  371. 'http://www.google.com/books/feeds/users/' .
  372. 'USER_ID/collections/library/volumes');
  373. $query->setCategory(
  374. $query->setCategory('favorites');
  375. $feed = $books->getVolumeFeed($query);
  376. ]]></programlisting>
  377. </sect4>
  378. </sect3>
  379. <sect3 id="zend.gdata.books.updating_library">
  380. <title>Updating books in a user's library</title>
  381. <para>
  382. You can use the Book Search Data <acronym>API</acronym> to add a book to, or remove a
  383. book from, a user's library. Ratings, reviews, and labels are valid
  384. across all the collections of a user, and are thus edited using the
  385. annotation feed (see <ulink
  386. url="#zend.gdata.books.community_features">Using community features</ulink>).
  387. </para>
  388. <sect4 id="zend.gdata.books.library_book_add">
  389. <title>Adding a book to a library</title>
  390. <para>
  391. After authenticating, you can add books to the current user's library.
  392. </para>
  393. <para>
  394. You can either create an entry from scratch if you
  395. know the volume ID, or insert an entry read from any feed.
  396. </para>
  397. <para>
  398. The following example creates a new entry and adds it to the library:
  399. </para>
  400. <programlisting language="php"><![CDATA[
  401. $entry = new Zend_Gdata_Books_VolumeEntry();
  402. $entry->setId(new Zend_Gdata_App_Extension_Id(VOLUME_ID));
  403. $books->insertVolume(
  404. $entry,
  405. Zend_Gdata_Books::MY_LIBRARY_FEED_URI
  406. );
  407. ]]></programlisting>
  408. <para>
  409. The following example adds an existing
  410. <code>VolumeEntry</code> object to the library:
  411. </para>
  412. <programlisting language="php"><![CDATA[
  413. $books->insertVolume(
  414. $entry,
  415. Zend_Gdata_Books::MY_LIBRARY_FEED_URI
  416. );
  417. ]]></programlisting>
  418. </sect4>
  419. <sect4 id="zend.gdata.books.library_book_remove">
  420. <title>Removing a book from a library</title>
  421. <para>
  422. To remove a book from a user's library, call
  423. <code>deleteVolume</code> on the <code>VolumeEntry</code> object.
  424. </para>
  425. <programlisting language="php"><![CDATA[
  426. $books->deleteVolume($entry);
  427. ]]></programlisting>
  428. </sect4>
  429. </sect3>
  430. </sect2>
  431. </sect1>