示例和演示
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
下面列出了 Embedded Viewer API 文档集中的所有示例以供快速参考。此外,还提供了许多其他演示来阐明高级概念。
开发者指南中的示例
开发者指南中提供了这些基本示例,并介绍了 Embedded Viewer API 的最常见用途。
- book-simple
Embedded Viewer API 的“Hello, World”示例,此示例指明了如何加载该 API 并绘制特定图书的查看者。
- book-language
此示例展示了如何将查看者的界面语言(在本例中为巴西葡萄牙语)更改为该语言。
- book-notfound
此代码展示了如何添加在查看者无法加载指定图书时调用的回调函数。您可以基于此示例进行构建,以妥善处理此类情况。
- book-success
这展示了如何添加回调函数,当查看者已成功使用某本图书进行初始化并准备好通过编程方式操作时,系统会调用该函数。
- book-Animated
为了说明如何使用 JavaScript 以编程方式控制查看器,我们展示了预览,每 3 秒会自动翻到下一页。
对查看者进行程序化控制
通过查看器,您可以使用代码执行用户可通过与其互动所能做的几乎任何操作。以下示例展示了它可能有何帮助。
与 Books API 和动态链接结合使用
构建高级应用时,您可能会发现将 Embedded Viewer API 与 Books API 或 Dynamic Links 功能结合使用会很有用。例如,提前了解特定预览是否可供嵌入(例如,确定是否为用户提供在您的网站上打开预览窗口的选项)可能很有用。或者,您可能不知道特定图书的标识符,但希望先使用 Books API 进行“查询”。以下示例说明了如何执行这些操作。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-06-28。
[null,null,["最后更新时间 (UTC):2024-06-28。"],[[["\u003cp\u003eThis documentation provides a comprehensive list of examples for Google Books Embedded Viewer API.\u003c/p\u003e\n"],["\u003cp\u003eExamples cover basic viewer setup, language settings, error handling, and programmatic control functionalities.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can learn to integrate the viewer with the Books API and Dynamic Links for advanced functionalities.\u003c/p\u003e\n"],["\u003cp\u003eSample code demonstrates interactions like zooming, navigation, and highlighting within the embedded viewer.\u003c/p\u003e\n"],["\u003cp\u003eUse cases include creating book previews, searching for books, and handling embedding availability.\u003c/p\u003e\n"]]],[],null,["# Examples and Demos\n\nAll of the examples contained within the Embedded Viewer API documentation set are listed below for quick reference. In addition, a number of additional demos are included to illustrate advanced concepts.\n\nExamples from the Developer's Guide\n-----------------------------------\n\nThese basic examples appear in the [Developer's Guide](/books/docs/viewer/developers_guide) and cover the most common uses of the Embedded Viewer API.\n\n- [book-simple](/books/docs/viewer/examples/book-simple) \n The \"Hello, World\" example of the Embedded Viewer API, this example indicates how to load the API and draw a viewer with a particular book.\n- [book-language](/books/docs/viewer/examples/book-language) \n This example shows how to change the viewer's interface language, in this case to Brazilian Portuguese.\n- [book-notfound](/books/docs/viewer/examples/book-notfound) \n This shows how to add a callback function which is called when the viewer could not load the specified book. You can build on this example to gracefully handle such conditions.\n- [book-success](/books/docs/viewer/examples/book-success) \n This shows how to add a callback function which is called when the viewer has successfully initialized with a book and is ready to be manipulated programatically.\n- [book-animate](/books/docs/viewer/examples/book-animate) \n To illustrate how the viewer can be controlled programmatically using JavaScript, a preview is shown which automatically flips to the next page every 3 seconds.\n\nProgrammatic control of the viewer\n----------------------------------\n\nThe viewer allows you to do with code almost anything the user can do by interacting with the the viewer. The examples below show how this might be useful.\n\n- [book-interactions-controls](/books/docs/viewer/examples/book-interactions-controls) \n This working example enumerates all the interaction methods supported by the viewer, including zoom, nextPage, goToPage, and highlighting functions.\n- [book-interactions-openatpage](/books/docs/viewer/examples/book-interactions-openatpage) \n Shows how to automatically open a book viewer on a particular page, using callbacks and the goToPage function.\n\nCombining with the Books API and Dynamic Links\n----------------------------------------------\n\nWhen building advanced applications, you may find it useful to combine\nthe Embedded Viewer API with either the [Books API](/books/docs/v1/getting_started) or the\n[Dynamic Links](/books/docs/dynamic-links)\nfeature. For example, it may be useful to know in advance whether a particular\npreview will be available for embedding (e.g., to determine whether to give the\nuser the option to open a preview window on your site). Or, you may not know the\nidentifier for a particular book, and want to first \"look it up\" using the Books\nAPI. The examples below indicate how to perform these operations.\n\n- [book-dynamiclinks-zippy](/books/docs/viewer/examples/book-dynamiclinks-zippy) \n Here we check whether a book is available for embedding first. If and only if it is available, we render a \"preview zippy,\" which, when clicked, shows the book preview inline.\n- [booksapi-titlesearch](/books/docs/viewer/examples/booksapi-titlesearch) \n This example allows you open an embedded viewer by simply entering a search query for a book. It will automatically show the first embeddable result for the query you enter. This uses the JSON output format of the Data API to access the search results."]]