ตัวอย่างและการสาธิต
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ตัวอย่างทั้งหมดที่อยู่ในชุดเอกสารประกอบของ Embedded Viewer API แสดงอยู่ในรายการด้านล่างสำหรับการอ้างอิงอย่างรวดเร็ว นอกจากนี้ยังมีการสาธิตเพิ่มเติมอีกจำนวนหนึ่งเพื่อแสดงให้เห็นภาพของแนวคิดขั้นสูง
ตัวอย่างจากคู่มือนักพัฒนาซอฟต์แวร์
ตัวอย่างพื้นฐานเหล่านี้ปรากฏในคู่มือนักพัฒนาซอฟต์แวร์และครอบคลุมการใช้งานทั่วไปของ API ผู้ดูแบบฝัง
- book-simple
ตัวอย่าง "Hello, World" ของ Embedded Viewer API ตัวอย่างนี้ระบุวิธีโหลด API และดึงดูดผู้ดูด้วยหนังสือเล่มใดเล่มหนึ่ง
- ภาษาหนังสือ
ตัวอย่างนี้แสดงวิธีเปลี่ยนภาษาอินเทอร์เฟซของผู้ดู ซึ่งในกรณีนี้เป็นภาษาโปรตุเกสแบบบราซิล
- ไม่พบหนังสือ
ส่วนนี้แสดงวิธีเพิ่มฟังก์ชัน Callback ซึ่งจะเรียกใช้เมื่อผู้ชมโหลดหนังสือที่ระบุไม่ได้ คุณอาจต่อยอดจากตัวอย่างนี้เพื่อจัดการกับเงื่อนไขดังกล่าวได้อย่างราบรื่น
- หนังสือสำเร็จ
ส่วนนี้จะแสดงวิธีเพิ่มฟังก์ชัน Callback ซึ่งระบบจะเรียกใช้เมื่อผู้ชมเริ่มอ่านหนังสือสำเร็จแล้วและพร้อมปรับเปลี่ยนเชิงโปรแกรม
- book-animate
เพื่อแสดงให้เห็นว่าวิธีควบคุมผู้ดูด้วยโปรแกรมโดยใช้ JavaScript จะแสดงตัวอย่างซึ่งจะพลิกไปยังหน้าถัดไปโดยอัตโนมัติทุกๆ 3 วินาที
การควบคุมแบบเป็นโปรแกรมของผู้ชม
โปรแกรมดูภาพจะช่วยให้คุณสามารถเขียนโค้ดได้เกือบทุกอย่างที่ผู้ใช้ทำได้โดยการโต้ตอบกับผู้ดู ตัวอย่างด้านล่างแสดงวิธีที่อาจมีประโยชน์
การผสานรวมกับ Books API และลิงก์แบบไดนามิก
เมื่อสร้างแอปพลิเคชันขั้นสูง คุณอาจพบว่าการรวม Embedded Viewer API เข้ากับ Books API หรือฟีเจอร์ลิงก์แบบไดนามิกมีประโยชน์ เช่น การรู้ล่วงหน้าว่าตัวอย่างหนึ่งๆ จะพร้อมใช้งานสำหรับการฝังหรือไม่ อาจเป็นประโยชน์ (เช่น ระบุว่าจะให้ผู้ใช้มีตัวเลือกที่จะเปิดหน้าต่างแสดงตัวอย่างในเว็บไซต์ของคุณหรือไม่) หรือคุณอาจไม่ทราบตัวระบุของหนังสือเล่มใดเล่มหนึ่ง และต้องการ "ค้นหา" โดยใช้ Books API ก่อน ตัวอย่างด้านล่างจะระบุวิธีดำเนินการ
- book-dynamiclinks-zippy
ที่นี่เราจะตรวจสอบว่าหนังสือพร้อมสำหรับการฝังหรือไม่ก่อน หากมีให้ใช้งานเท่านั้น เราจะแสดงผล " Zippy ตัวอย่าง" ซึ่งเมื่อคลิกจะแสดงตัวอย่างหนังสือในบรรทัด
- booksapi-titlesearch
ตัวอย่างนี้ให้คุณเปิดมุมมองที่ฝังอยู่ได้ง่ายๆ ด้วยการป้อนคำค้นหาสำหรับหนังสือ ซึ่งจะแสดงผลลัพธ์ที่ฝังได้รายการแรกสำหรับข้อความค้นหาที่คุณป้อนโดยอัตโนมัติ การดำเนินการนี้ใช้รูปแบบเอาต์พุต JSON ของ Data API เพื่อเข้าถึงผลการค้นหา
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 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."]]