เริ่มต้นใช้งาน Library API
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
Library API ช่วยให้คุณโต้ตอบกับรูปภาพ วิดีโอ และอัลบั้มภายในคลังภาพ Google Photos ของผู้ใช้ได้ แต่มีข้อจำกัดสำคัญคือคุณจะเข้าถึงและจัดการได้เฉพาะเนื้อหาที่สร้างโดยแอปพลิเคชันของคุณเท่านั้น
ก่อนจะเริ่ม
กรณีการใช้งานที่สำคัญของ Library API
Library API เหมาะสำหรับกรณีที่แอปจำเป็นต้องดำเนินการต่อไปนี้
- อัปโหลดและจัดเก็บสื่อ: นําเข้ารูปภาพและวิดีโอ (ที่สร้างโดยแอปของคุณ) ไปยังคลังภาพ Google Photos ของผู้ใช้อย่างปลอดภัย
- จัดระเบียบเนื้อหา: สร้างและจัดการอัลบั้มเพื่อช่วยผู้ใช้จัดระเบียบสื่อที่เกี่ยวข้องกับแอป
- เพิ่มประสิทธิภาพรูปภาพและอัลบั้ม: เพิ่มบริบทให้กับรายการสื่อและอัลบั้มผ่านการเพิ่มประสิทธิภาพ เช่น ชื่อ คำอธิบาย หรือข้อมูลตำแหน่ง
- เข้าถึงข้อมูลที่แอปสร้างขึ้น: เรียกดูและโต้ตอบกับรูปภาพ วิดีโอ
และอัลบั้มที่แอปสร้างไว้ก่อนหน้านี้
เวิร์กโฟลว์ทั่วไปของ Library API
แม้ว่า Library API จะมีฟังก์ชันการทำงานที่หลากหลาย แต่เวิร์กโฟลว์ทั่วไปอาจมีขั้นตอนเหล่านี้
อัปโหลดสื่อ: ใช้ปลายทางการอัปโหลดเพื่ออัปโหลดไบต์รูปภาพหรือวิดีโอไปยัง Google Photos อย่างปลอดภัย ขั้นตอนนี้จะสร้าง uploadToken
สร้างรายการสื่อ: ใช้เมธอด mediaItems.batchCreate
โดยระบุ uploadToken
เพื่อสร้างรายการสื่อในไลบรารีของผู้ใช้
สร้างอัลบั้ม (ไม่บังคับ): ใช้วิธีการ albums.create
สร้างอัลบั้มภายในคลังภาพของผู้ใช้เพื่อจัดระเบียบรายการสื่อ
จัดการอัลบั้ม
เข้าถึงสื่อที่สร้างในแอป
- เรียกดูรายละเอียดเกี่ยวกับรายการสื่อที่เฉพาะเจาะจงโดยใช้
mediaItems.get
หรือ
mediaItems.batchGet
- ค้นหารายการสื่อที่สร้างโดยแอปของคุณโดยใช้
mediaItems.search
- แสดงรายการสื่อภายในอัลบั้มที่สร้างขึ้นโดยแอปที่เฉพาะเจาะจงโดยใช้
mediaItems.search
พร้อมรหัสอัลบั้ม
ขั้นตอนถัดไป
- อ่านเอกสารอ้างอิง: สํารวจเอกสารอ้างอิง Library API โดยละเอียดเพื่อดูข้อมูลเกี่ยวกับเมธอดและพารามิเตอร์ทั้งหมดที่ใช้ได้
- ลองใช้ตัวอย่าง: ดูตัวอย่างของเราเพื่อดูการทำงานของ Library API จริงและรับแรงบันดาลใจสําหรับการผสานรวมของคุณ
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-29 UTC
[null,null,["อัปเดตล่าสุด 2025-08-29 UTC"],[[["\u003cp\u003eThe Library API allows your application to interact with photos, videos, and albums in users' Google Photos libraries, but only for content created by your application.\u003c/p\u003e\n"],["\u003cp\u003eKey use cases include uploading/storing media, organizing content into albums, enhancing media with details, and accessing previously created app data.\u003c/p\u003e\n"],["\u003cp\u003eA typical workflow involves uploading media, creating media items, optionally creating and managing albums, and accessing the app-created media.\u003c/p\u003e\n"],["\u003cp\u003eBefore starting, ensure the Library API aligns with your needs by reviewing the overview and configuring your app for API access.\u003c/p\u003e\n"]]],["The Library API enables interaction with Google Photos, specifically for app-created content. Key actions include uploading media using an `uploadToken`, creating media items in the user's library, and optionally organizing them into albums. You can also manage albums by adding or removing media, adding enrichments, and retrieving album information. The API allows retrieval and searching of app-created media items. The first step before starting to use this API is to configure your application and ensure the Library API is suitable for your use case.\n"],null,["# Get started with the Library API\n\nThe Library API lets you to interact with photos, videos, and albums within your\nusers' Google Photos libraries, but with an important focus: you can only access\nand manage content that was created by your application.\n\nBefore you start\n----------------\n\n- **Check out the overview:** [Compare the Picker API and the Library API](/photos/overview/about) to make sure the Library API is the right fit for your use case.\n- **Configure Your app:** Enable the API and set up authentication. See [Configure your app](/photos/overview/configure-your-app) for detailed steps.\n\nKey use cases of the Library API\n--------------------------------\n\nThe Library API is ideal for scenarios where your app needs to:\n\n- **Upload and store media:** Securely import photos and videos (generated by your app) into your users' Google Photos libraries.\n- **Organize content:** Create and manage albums to help users organize their app-related media.\n- **Enhance photos and albums:** Add context to media items and albums through enrichments like titles, descriptions, or location information.\n- **Access app-created data:** Retrieve and interact with the photos, videos, and albums that your app has previously created.\n\nTypical Library API workflow\n----------------------------\n\nWhile the Library API offers various functionalities, a common workflow might\ninvolve these steps:\n\n1. **Upload media:** Use the [uploads endpoint](/photos/library/guides/upload-media)\n to securely upload photo or video bytes to Google Photos. This step\n generates an\n [`uploadToken`](/photos/library/reference/rest/v1/mediaItems/batchCreate#SimpleMediaItem.FIELDS.upload_token).\n\n2. **Create media items:** Use the [`mediaItems.batchCreate`\n method](/photos/library/guides/upload-media#creating-media-item), providing\n the `uploadToken`, to create media items in the user's library.\n\n3. **Create albums (optional):** Use the [`albums.create` method](/photos/library/guides/manage-albums#creating-new-album)\n to create albums within the user's library to organize the media items.\n\n4. **Manage albums:**\n\n - Add media items (created by your app) to albums using [`albums.batchAddMediaItems`.](/photos/library/guides/manage-albums#adding-items-to-album)\n - Remove media items from albums using [`albums.batchRemoveMediaItems`](/photos/library/guides/manage-albums#removing-items-from-album).\n - Add enrichments to albums (like titles or locations) using [`albums.addEnrichment`.](/photos/library/guides/add-enrichments#intro-adding-enrichments-album)\n - Retrieve information about specific albums using [`albums.get`](/photos/library/guides/list#listing-albums).\n - List albums created by your app using [`albums.list`](/photos/library/guides/list#listing-albums).\n5. **Access app-created media:**\n\n - Retrieve details about specific media items using `mediaItems.get` or `mediaItems.batchGet`.\n - Search for media items created by your app using `mediaItems.search`.\n - List media items within a specific app-created album using `mediaItems.search` with the album ID.\n\nNext steps\n----------\n\n- Review the reference docs: Explore the detailed [Library API reference\n documentation](/photos/library/reference/rest) to learn about all the available methods and parameters.\n- Try out the samples: Check out our [sample](/photos/library/samples) to see the Library API in action and get inspiration for your integration."]]