Làm quen với Library API
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
API Thư viện cho phép bạn tương tác với ảnh, video và album trong thư viện Google Photos của người dùng, nhưng có một điểm quan trọng là bạn chỉ có thể truy cập và quản lý nội dung do ứng dụng của bạn tạo ra.
Trước khi bắt đầu
Các trường hợp sử dụng chính của API Thư viện
Library API là lựa chọn lý tưởng cho các trường hợp ứng dụng của bạn cần:
- Tải lên và lưu trữ nội dung nghe nhìn: Nhập ảnh và video (do ứng dụng của bạn tạo) một cách an toàn vào thư viện Google Photos của người dùng.
- Sắp xếp nội dung: Tạo và quản lý album để giúp người dùng sắp xếp nội dung nghe nhìn liên quan đến ứng dụng của họ.
- Cải thiện ảnh và album: Thêm ngữ cảnh vào các mục nội dung nghe nhìn và album thông qua các thông tin bổ sung như tiêu đề, nội dung mô tả hoặc thông tin vị trí.
- Truy cập vào dữ liệu do ứng dụng tạo: Truy xuất và tương tác với ảnh, video và album mà ứng dụng của bạn đã tạo trước đó.
Quy trình điển hình của API Thư viện
Mặc dù Thư viện API cung cấp nhiều chức năng, nhưng quy trình làm việc phổ biến có thể bao gồm các bước sau:
Tải nội dung nghe nhìn lên: Sử dụng điểm cuối tải lên để tải các byte ảnh hoặc video lên Google Photos một cách an toàn. Bước này sẽ tạo một uploadToken
.
Tạo mục nội dung nghe nhìn: Sử dụng phương thức mediaItems.batchCreate
, cung cấp uploadToken
để tạo mục nội dung nghe nhìn trong thư viện của người dùng.
Tạo album (không bắt buộc): Sử dụng phương thức albums.create
để tạo album trong thư viện của người dùng nhằm sắp xếp các mục nội dung nghe nhìn.
Quản lý album:
Truy cập nội dung nghe nhìn do ứng dụng tạo:
- Truy xuất thông tin chi tiết về các mục nội dung nghe nhìn cụ thể bằng
mediaItems.get
hoặc
mediaItems.batchGet
.
- Tìm kiếm các mục nội dung nghe nhìn do ứng dụng của bạn tạo bằng
mediaItems.search
.
- Liệt kê các mục nội dung nghe nhìn trong một đĩa nhạc cụ thể do ứng dụng tạo bằng cách sử dụng
mediaItems.search
với mã đĩa nhạc.
Các bước tiếp theo
- Xem lại tài liệu tham khảo: Khám phá tài liệu tham khảo API Thư viện chi tiết để tìm hiểu về tất cả các phương thức và tham số hiện có.
- Thử các mẫu: Hãy xem mẫu của chúng tôi để xem Thư viện API hoạt động và lấy cảm hứng cho quá trình tích hợp.
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-08-29 UTC.
[null,null,["Cập nhật lần gần đây nhất: 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."]]