例とデモ
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
Embedded Viewer API ドキュメント セットに含まれるすべての例は、簡単に参照できるようにまとめられています。さらに、高度なコンセプトを説明するデモも多数含まれています。
デベロッパー ガイドの例
デベロッパー ガイドにはこれらの基本的な例が掲載されており、Embedded Viewer API の一般的な用途について説明しています。
- book-simple
Embedded Viewer API の「Hello, World」の例では、API を読み込んで特定の書籍のビューアを描画する方法を示しています。
- book-language
次の例は、閲覧者のインターフェース言語(この場合はブラジル ポルトガル語)を変更する方法を示しています。
- book-notfound
これは、閲覧者が指定された書籍を読み込めなかったときに呼び出されるコールバック関数の追加方法を示しています。この例を基にして、このような条件を適切に処理できます。
- book-success
これは、閲覧者が書籍で正常に初期化され、プログラムによる操作の準備が整ったときに呼び出されるコールバック関数の追加方法を示しています。
- book-Animation
JavaScript を使用してプログラムによってビューアがどのように制御されるかを説明するため、3 秒ごとに自動的に次のページに切り替わるプレビューが表示されます。
プログラムによる閲覧者の制御
ビューアでは、ビューアを操作してユーザーが実行できるほぼすべての操作を行うことができます。以下の例は、これがどのように役立つかを示しています。
ブックス API および Dynamic Links との併用
高度なアプリケーションを構築する場合は、Embedded Viewer API を Books API または Dynamic Links 機能と組み合わせると便利です。たとえば、特定のプレビューが埋め込み可能かどうかを事前に把握しておくと便利です(サイトでプレビュー ウィンドウを開くオプションをユーザーに提供するかどうかを指定する場合など)。特定の書籍の ID がわからない場合には、まず Books API を使用して「検索」する必要があります。以下の例は、これらの操作の実行方法を示しています。
- book-dynamiclinks-zippy
最初に、書籍が埋め込みが可能なかどうかをチェックします。利用可能な場合にのみ、「preview zippy」を表示します。これをクリックすると、書籍のプレビューがインライン表示されます。
- booksapi-titlesearch
この例では、書籍の検索クエリを入力するだけで埋め込みビューアを開くことができます。入力したクエリの最初の埋め込み可能な結果が自動的に表示されます。Data API の JSON 出力形式を使用して検索結果にアクセスします。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2024-06-28 UTC。
[null,null,["最終更新日 2024-06-28 UTC。"],[[["\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."]]