範例與示範
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
下方列出 Embedded Viewer API 說明文件集中的所有範例,可供您快速參考。除此之外,我們還有一些額外示範來說明進階概念。
開發人員指南中的範例
這些基本範例列載於開發人員指南中,並說明 Embedded Viewer API 的最常見用途。
- book-simple
對於嵌入式檢視器 API 中的「Hello, World」範例,這個範例說明如何載入 API 並繪製特定書籍的檢視器。
- 書籍語言
這個範例說明如何將檢視者的介面語言變更為巴西葡萄牙文。
- book-notfound
展示如何新增在檢視者無法載入指定書籍時呼叫的回呼函式。您可以參考本範例的建構方式,妥善處理這類情況。
- 書籍成功
展示如何新增回呼函式。當檢視者成功初始化書籍,且現在可以透過程式化操作時,系統會呼叫此回呼函式。
- 書籍動畫
為示範使用者如何透過 JavaScript 操控檢視器,系統會顯示預覽畫面,每隔 3 秒自動翻頁一次。
透過程式輔助方式控管觀眾
透過觀眾與觀眾互動,您幾乎可以執行任何程式碼。以下範例呈現了這項功能的實用程度。
與 Books API 和 Dynamic Links 搭配使用
建構進階應用程式時,建議您將 Embedded Viewer API 與 Books API 或 Dynamic Links 功能結合使用。舉例來說,事先得知特定預覽功能是否支援嵌入 (例如,決定是否提供使用者在網站上開啟預覽視窗的選項),可能會很有幫助。或者,您可能不知道特定書籍的 ID,但想先使用 Books API 「查詢」。以下範例說明如何執行這些作業。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2024-06-28 (世界標準時間)。
[null,null,["上次更新時間: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."]]