จัดการอัลบั้ม
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ใน Google Photos คุณสามารถจัดระเบียบรูปภาพและรายการสื่ออื่นๆ โดยใช้อัลบั้ม
สามารถเชื่อมโยงรายการสื่อกับอัลบั้มได้อย่างน้อย 1 รายการ หากต้องการเริ่มเชื่อมโยงรายการสื่อกับอัลบั้ม คุณต้องสร้างอัลบั้มก่อน
ขอบเขตการให้สิทธิ์ที่จําเป็น
การสร้างอัลบั้มต้องใช้ขอบเขต photoslibrary.appendonly
การเปลี่ยนชื่อหรือรูปภาพปกของอัลบั้มหลังจากสร้างต้องใช้ขอบเขต
photoslibrary.edit.appcreateddata
ดูข้อมูลเพิ่มเติมเกี่ยวกับขอบเขตได้ที่ขอบเขตการให้สิทธิ์
สร้างอัลบั้มใหม่
หากต้องการสร้างอัลบั้ม ให้เรียกใช้ albums.create
และใส่ title
โปรดทราบว่า title
มีความยาวได้ไม่เกิน 500 อักขระ
การเรียกใช้จะแสดงผลอัลบั้ม แอปของคุณสามารถจัดเก็บรหัสอัลบั้มจากข้อมูลนี้และใช้เพื่ออัปโหลดรายการสื่อไปยังอัลบั้มที่ต้องการ
REST
ต่อไปนี้เป็นส่วนหัวสำหรับคำขอ POST:
POST https://photoslibrary.googleapis.com/v1/albums
Content-type: application/json
Authorization: Bearer oauth2-token
เนื้อหาคําขอมีลักษณะดังนี้
{
"album": {
"title": "new-album-title"
}
}
หากดำเนินการสำเร็จ การตอบกลับจะแสดงอัลบั้มดังนี้
{
"productUrl": "album-product-url",
"id": "album-id",
"title": "album-title",
"isWriteable": "whether-you-can-write-to-this-album"
}
เรียกข้อมูลรายละเอียดอัลบั้ม
หากต้องการเรียกดูรายละเอียดของอัลบั้มที่มีอยู่ซึ่งแอปของคุณสร้างขึ้น โปรดโทรไปที่ albums.get
และระบุ albumId
ของอัลบั้มที่คุณต้องการดึงข้อมูล
การเรียกใช้จะแสดงผลอัลบั้ม
REST
ส่วนหัวของคำขอ GET มีดังนี้
GET https://photoslibrary.googleapis.com/v1/albums/{albumId}
Content-type: application/json
Authorization: Bearer oauth2-token
เนื้อหาคําขอมีลักษณะดังนี้
{
"albumId": album-id
}
หากสำเร็จ การตอบกลับจะแสดงอัลบั้มดังนี้
{
"id": album-id,
"title": album-title,
"productUrl": album-product-url,
"mediaItemsCount": media-items-count,
"coverPhotoBaseUrl": cover-photo-base-url,
"coverPhotoMediaItemId": cover-photo-media-item-id
}
เปลี่ยนชื่ออัลบั้มและรูปภาพปก
หากต้องการเปลี่ยนชื่อหรือรูปภาพปกของอัลบั้ม ให้สร้าง album update
call
ที่มีตัวระบุของอัลบั้ม และระบุชื่อใหม่หรือรหัสรายการสื่อของรูปภาพปกใหม่ในคำขอ คุณต้องใช้ขอบเขต photoslibrary.edit.appcreateddata
authorization เพื่อทําการเปลี่ยนแปลง
ชื่ออัลบั้มต้องมีความยาวไม่เกิน 500 อักขระ รายการสื่อหน้าปกต้องเป็นของเจ้าของอัลบั้มและเป็นส่วนหนึ่งของอัลบั้มที่จะใช้เป็นเพลงคัฟเวอร์
REST
ส่วนหัวคำขอ PATCH สำหรับอัปเดต title
และ coverPhotomediaItemId
ของอัลบั้มมีดังนี้
PATCH https://photoslibrary.googleapis.com/v1/albums/album-id?updateMask=title&updateMask=coverPhotoMediaItemId
คำขอนี้จะระบุว่าพร็อพเพอร์ตี้ใดกำลังอัปเดตอยู่โดยใส่มาสก์ของช่อง ซึ่งระบุโดยพารามิเตอร์ updateMask
ใน URL คุณต้องส่งพารามิเตอร์ updateMask
สำหรับที่พักแต่ละแห่งที่จะอัปเดต
สำหรับที่พักแต่ละแห่งที่อัปเดต ให้ใส่รายละเอียดของที่พักนั้นในเนื้อหาของคำขอ
{
"title": "new-album-title",
"coverPhotoMediaItemId": "new-cover-media-item-id"
}
หากดำเนินการสำเร็จ การตอบกลับจะแสดงรายละเอียด album
ที่อัปเดตแล้ว ดังนี้
{
"id": "album-id",
"title": "new-album-title",
"productUrl": "album-product-url",
"isWriteable": "true-if-user-can-write-to-this-album",
"mediaItemsCount": "number-of-media-items-in-album",
"coverPhotoBaseUrl": "cover-photo-base-url_use-only-with-parameters",
"coverPhotoMediaItemId": "new-cover-media-item-id"
}
เพิ่มรายการสื่อลงในอัลบั้ม
คุณสามารถเพิ่มรายการสื่อที่แอปของคุณสร้างขึ้นลงในอัลบั้มที่แอปของคุณสร้างขึ้นได้โดยการเรียกใช้ albums.batchAddMediaItems
ระบบจะเพิ่มรายการสื่อไว้ท้ายอัลบั้มตามลำดับที่ระบุในการเรียกใช้นี้
คำขอทั้งหมดจะดำเนินการไม่สำเร็จหากระบุรายการสื่อหรืออัลบั้มที่ไม่ถูกต้อง
ระบบไม่รองรับความสำเร็จบางส่วน
แต่ละอัลบั้มมีรายการสื่อได้สูงสุด 20,000 รายการ คำขอเพิ่มรายการที่จะเกินขีดจำกัดนี้จะดำเนินการไม่สำเร็จ
หากต้องการเพิ่มรายการสื่อลงในอัลบั้ม ให้เรียก albums.batchAddMediaItems
ที่มีตัวระบุของรายการสื่อและอัลบั้ม
REST
ต่อไปนี้เป็นส่วนหัวสำหรับคำขอ POST:
POST https://photoslibrary.googleapis.com/v1/albums/album-id:batchAddMediaItems
Content-type: application/json
Authorization: Bearer oauth2-token
เนื้อหาของคำขอมีลักษณะดังนี้
{
"mediaItemIds": [
"media-item-id",
"another-media-item-id",
...
]
}
หากดำเนินการสำเร็จ ระบบจะแสดงการตอบกลับ JSON ว่างเปล่าและสถานะ HTTP สำเร็จ
นำรายการสื่อออกจากอัลบั้ม
คุณนำรายการสื่อที่แอปสร้างขึ้นออกจากอัลบั้มที่แอปสร้างได้โดยเรียกใช้ albums.batchRemoveMediaItems
คำขอทั้งหมดจะดำเนินการไม่สำเร็จหากระบุรายการสื่อที่ไม่ถูกต้อง ระบบไม่รองรับ "บางส่วนสำเร็จ"
หากต้องการนำรายการสื่อออกจากอัลบั้ม ให้เรียกใช้ albums.batchRemoveMediaItems
พร้อมตัวระบุของรายการสื่อและอัลบั้ม
REST
ต่อไปนี้เป็นส่วนหัวสำหรับคำขอ POST:
POST https://photoslibrary.googleapis.com/v1/albums/album-id:batchRemoveMediaItems
Content-type: application/json
Authorization: Bearer oauth2-token
เนื้อหาของคำขอมีลักษณะดังนี้
{
"mediaItemIds": [
"media-item-id",
"another-media-item-id",
...
]
}
หากดำเนินการสำเร็จ ระบบจะแสดงการตอบกลับ JSON ว่างเปล่าและสถานะ HTTP สำเร็จ
Java
try {
// List of media item IDs to remove
List<String> mediaItemIds = Arrays
.asList("MEDIA_ITEM_ID", "ANOTHER_MEDIA_ITEM_ID");
// ID of the album to remove media items from
String albumId = "ALBUM_ID";
// Remove all given media items from the album
photosLibraryClient.batchRemoveMediaItemsFromAlbum(albumId, mediaItemIds);
} catch (ApiException e) {
// An exception is thrown if the media items could not be removed
}
PHP
try {
// List of media item IDs to remove
$mediaItemIds = ["MEDIA_ITEM_ID", "ANOTHER_MEDIA_ITEM_ID"];
// ID of the album to remove media items from
$albumId = "ALBUM_ID";
// Remove all given media items from the album
$response = $photosLibraryClient->batchRemoveMediaItemsFromAlbum($albumId, $mediaItemIds);
} catch (\Google\ApiCore\ApiException $e) {
// Handle Error
}
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-09-04 UTC
[[["เข้าใจง่าย","easyToUnderstand","thumb-up"],["แก้ปัญหาของฉันได้","solvedMyProblem","thumb-up"],["อื่นๆ","otherUp","thumb-up"]],[["ไม่มีข้อมูลที่ฉันต้องการ","missingTheInformationINeed","thumb-down"],["ซับซ้อนเกินไป/มีหลายขั้นตอนมากเกินไป","tooComplicatedTooManySteps","thumb-down"],["ล้าสมัย","outOfDate","thumb-down"],["ปัญหาเกี่ยวกับการแปล","translationIssue","thumb-down"],["ตัวอย่าง/ปัญหาเกี่ยวกับโค้ด","samplesCodeIssue","thumb-down"],["อื่นๆ","otherDown","thumb-down"]],["อัปเดตล่าสุด 2025-09-04 UTC"],[[["\u003cp\u003eIn Google Photos, albums are used to organize photos and media items, with each item able to belong to multiple albums.\u003c/p\u003e\n"],["\u003cp\u003eYou can create, retrieve details of, and modify albums using the Google Photos Library API.\u003c/p\u003e\n"],["\u003cp\u003eThe API also allows you to add and remove media items from albums, managing their association.\u003c/p\u003e\n"],["\u003cp\u003eDifferent authorization scopes are required for creating albums and for changing their titles or cover photos, ensuring controlled access.\u003c/p\u003e\n"],["\u003cp\u003eEach album has a limit of 20,000 media items, and requests exceeding this limit will fail.\u003c/p\u003e\n"]]],["Google Photos allows album creation and management via API calls. Creating an album requires the `photoslibrary.appendonly` scope, while editing needs `photoslibrary.edit.appcreateddata`. Albums are created using `albums.create` with a title (max 500 characters). Details are retrieved with `albums.get` using the `albumId`. Titles and cover photos are updated with `albums.patch` by specifying the parameters to be modified. Media items are added and removed using `albums.batchAddMediaItems` and `albums.batchRemoveMediaItems` respectively, using media item IDs.\n"],null,["# Manage albums\n\nIn Google Photos, you can organize photos and other media items using albums.\nA media item can be associated with one or more albums. To start associating\nmedia items with an album, you need to create the album first.\n\nRequired authorization scopes\n-----------------------------\n\nCreating albums requires the `photoslibrary.appendonly` scope.\n\nChanging the title or cover photo of albums after their creation requires the\n`photoslibrary.edit.appcreateddata` scope.\n\nFor more information on scopes, see [Authorization\nscopes](/photos/overview/authorization).\n\nCreate a new album\n------------------\n\nTo create an album, call\n[`albums.create`](/photos/library/reference/rest/v1/albums/create) and include\nthe `title`. Note that `title` is restricted to 500 characters.\n\nThe call returns an [album](/photos/library/reference/rest/v1/albums). Your app\ncan store the album ID from this information and use it for [uploading media\nitems](/photos/library/guides/upload-media) to the specific album. \n\n### REST\n\nHere is a header for a POST request: \n\n```\nPOST https://photoslibrary.googleapis.com/v1/albums\nContent-type: application/json\nAuthorization: Bearer oauth2-token\n```\n\nThe request body looks like this: \n\n```restructuredtext\n{\n \"album\": {\n \"title\": \"new-album-title\"\n }\n}\n```\n\nIf successful, the response returns an\n[album](/photos/library/reference/rest/v1/albums): \n\n```restructuredtext\n{\n \"productUrl\": \"album-product-url\",\n \"id\": \"album-id\",\n \"title\": \"album-title\",\n \"isWriteable\": \"whether-you-can-write-to-this-album\"\n}\n```\n\nRetrieve album details\n----------------------\n\nTo retrieve the details of an existing album created by your app, call\n[`albums.get`](/photos/library/reference/rest/v1/albums/get) and include the\n`albumId` of the album you want to fetch.\n\nThe call returns an [album](/photos/library/reference/rest/v1/albums). \n\n### REST\n\nHere is a header for a GET request: \n\n```\nGET https://photoslibrary.googleapis.com/v1/albums/{albumId}\nContent-type: application/json\nAuthorization: Bearer oauth2-token\n```\n\nThe request body looks like this: \n\n```restructuredtext\n{\n \"albumId\": album-id\n}\n```\n\nIf successful, the response returns an\n[album](/photos/library/reference/rest/v1/albums): \n\n```restructuredtext\n{\n \"id\": album-id,\n \"title\": album-title,\n \"productUrl\": album-product-url,\n \"mediaItemsCount\": media-items-count,\n \"coverPhotoBaseUrl\": cover-photo-base-url,\n \"coverPhotoMediaItemId\": cover-photo-media-item-id\n}\n```\n\nChange album titles and cover photos\n------------------------------------\n\nTo change an album title or cover photo, make an [`album update\ncall`](/photos/library/reference/rest/v1/albums/patch) with the identifier of\nthe album, and include the new title or the new cover photo's media item ID in\nthe request. You'll need to use the `photoslibrary.edit.appcreateddata`\n[authorization](/photos/library/guides/authorization) scope to make the change.\n\nAlbum titles can be no more than 500 characters in length. Cover media items\nmust be owned by the album owner, and belong to the album they will be a cover\nfor. \n\n### REST\n\nHere's a PATCH request header to update an album's `title` and\n`coverPhotomediaItemId`. \n\n```\nPATCH https://photoslibrary.googleapis.com/v1/albums/album-id?updateMask=title&updateMask=coverPhotoMediaItemId\n```\n\nThis request determines what properties are being updated by including\na field mask, indicated by the `updateMask` parameters in the\nURL. The `updateMask` parameter needs to be passed for each\nalbum property that is being updated.\n\nFor each property you are updating, include its details in\nthe body of the request: \n\n```restructuredtext\n{\n \"title\": \"new-album-title\",\n \"coverPhotoMediaItemId\": \"new-cover-media-item-id\"\n}\n```\n\nIf successful, the response returns the updated `album`\ndetails: \n\n```restructuredtext\n{\n \"id\": \"album-id\",\n \"title\": \"\u003cvar translate=\"no\"\u003enew-album-title\u003c/var\u003e\",\n \"productUrl\": \"album-product-url\",\n \"isWriteable\": \"true-if-user-can-write-to-this-album\",\n \"mediaItemsCount\": \"number-of-media-items-in-album\",\n \"coverPhotoBaseUrl\": \"/photos/library/guides/access-media-items#base-urls\",\n \"coverPhotoMediaItemId\": \"\u003cvar translate=\"no\"\u003enew-cover-media-item-id\u003c/var\u003e\"\n}\n```\n\nAdd media items to an album\n---------------------------\n\nYou can add media items created by your app to albums created by your app by\ncalling\n[`albums.batchAddMediaItems`](/photos/library/reference/rest/v1/albums/batchAddMediaItems).\nMedia items are added to the end of the album in the order given in this call.\n\nThe entire request will fail if an invalid media item or album is specified.\nPartial success is not supported.\n\nEach album can contain up to 20,000 media items. Requests to add more items that\nwould exceed this limit will fail.\n\nTo add media items to an album, call\n[`albums.batchAddMediaItems`](/photos/library/reference/rest/v1/albums/batchAddMediaItems)\nwith the identifiers of the media items and the album. \n\n### REST\n\nHere is a header for a POST request: \n\n```\nPOST https://photoslibrary.googleapis.com/v1/albums/album-id:batchAddMediaItems\nContent-type: application/json\nAuthorization: Bearer oauth2-token\n```\n\nThe request body looks like this: \n\n```restructuredtext\n{\n \"mediaItemIds\": [\n \"media-item-id\",\n \"another-media-item-id\",\n ...\n ]\n}\n```\n\nIf successful, the response returns an empty JSON response and the HTTP\nSuccess status.\n\nRemove media items from an album\n--------------------------------\n\nYou can remove media items created by your app to albums created by your app by\ncalling\n[`albums.batchRemoveMediaItems`](/photos/library/reference/rest/v1/albums/batchRemoveMediaItems).\n\nThe entire request will fail if invalid media items are specified. Partial\nsuccess is not supported.\n\nTo remove media items from an album, call\n[`albums.batchRemoveMediaItems`](/photos/library/reference/rest/v1/albums/batchRemoveMediaItems)\nwith the identifiers of the media items and the album. \n\n### REST\n\nHere is a header for a POST request: \n\n```\nPOST https://photoslibrary.googleapis.com/v1/albums/album-id:batchRemoveMediaItems\nContent-type: application/json\nAuthorization: Bearer oauth2-token\n```\n\nThe request body looks like this: \n\n```restructuredtext\n{\n \"mediaItemIds\": [\n \"media-item-id\",\n \"another-media-item-id\",\n ...\n ]\n}\n```\n\nIf successful, the response returns an empty JSON response and the HTTP\nSuccess status.\n\n### Java\n\n```java\ntry {\n // List of media item IDs to remove\n List\u003cString\u003e mediaItemIds = Arrays\n .asList(\"MEDIA_ITEM_ID\", \"ANOTHER_MEDIA_ITEM_ID\");\n\n // ID of the album to remove media items from\n String albumId = \"ALBUM_ID\";\n\n // Remove all given media items from the album\n photosLibraryClient.batchRemoveMediaItemsFromAlbum(albumId, mediaItemIds);\n\n} catch (ApiException e) {\n // An exception is thrown if the media items could not be removed\n}\n```\n\n### PHP\n\n```php\ntry {\n\n // List of media item IDs to remove\n $mediaItemIds = [\"MEDIA_ITEM_ID\", \"ANOTHER_MEDIA_ITEM_ID\"];\n\n // ID of the album to remove media items from\n $albumId = \"ALBUM_ID\";\n\n // Remove all given media items from the album\n $response = $photosLibraryClient-\u003ebatchRemoveMediaItemsFromAlbum($albumId, $mediaItemIds);\n\n} catch (\\Google\\ApiCore\\ApiException $e) {\n // Handle Error\n}\n```"]]