Zend_Gdata_Books.xml 22 KB

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