強化功能可讓應用程式控制 Google 相簿的相簿內的相片。這能讓您 例如文字或地點註解,以及順序/群組來補充背景資訊 可以將故事設為故事內容的圖片
必要的授權範圍
至少須設定下列其中一個範圍,才能新增擴充功能:
photoslibrary.appendonly
photoslibrary.library
photoslibrary.sharing
針對每個範圍,enrichAlbum
呼叫僅限於建立的相簿
。
使用 .sharing
範圍時,enrichAlbum
只能在特定情況下使用
開發人員的代理人。
充實類型
Google 相簿支援在相簿中使用三種充實功能:文字、 位置和地圖。
文字擴充
文字擴充是一種純文字字串,可插入以註解 專輯
地點詳細資訊
地點擴充資訊是標記和可插入的地點名稱 即可為地點加上註解
地圖充實內容
地圖擴充資料是指定起點和目的地的地圖 已插入相簿。
位置
如要插入媒體項目和相簿擴充項目,請指定相簿位置。 您可以為媒體項目選擇位置,但必須為相簿指定位置 以便快速擷取
只有在下列情況中,才能指定位置: 建立媒體項目 或新增擴充項目您無法重新整理相簿中現有的媒體項目,因此 請務必在項目新增時設定項目的位置。
相簿開頭
您可在相簿開頭加入媒體/充實項目做為絕對大小 位置。
專輯結束時
媒體/充實項目會以絕對檔案的形式新增到相簿末端 位置。
相對於媒體項目
您可以在 相片在相簿中的位置。
相對於豐富項目
可根據擴充項目開頭新增媒體/充實項目 。
在相簿中加入擴充功能
系統一次會新增一個多元化作品,且您必須將這些圖層新增至相簿的位置上。
如要在相簿中加入充實功能,請呼叫
albums.addEnrichment
。
如果要求成功,會傳回擴充項目的 id
,
可用於定位媒體項目或其他擴充項目的位置。
REST
以下是 POST 要求:
POST https://photoslibrary.googleapis.com/v1/albums/album-id:addEnrichment Content-type: application/json Authorization: Bearer oauth2-token request-body
要求主體包含擴充項目及其位置:
{ "newEnrichmentItem": { enrichment-to-be-added }, "albumPosition": { position-of-enrichment }
以下是回應範例:
{ "enrichmentItem": { "id": "enrichment-item-id", } }
Java
try { // Create the enrichment using the NewEnrichmentItemFactory helper NewEnrichmentItem newEnrichmentItem = NewEnrichmentItemFactory.createTextEnrichment(""); // Set the position of the enrichment within the album AlbumPosition albumPosition = AlbumPositionFactory.createFirstInAlbum(); // To add an enrichment, specify the album, the enrichment item, // and the position in the album where the enrichment is to be added AddEnrichmentToAlbumResponse response = photosLibraryClient .addEnrichmentToAlbum(albumId, newEnrichmentItem, albumPosition); // The response contains an EnrichmentItem // whose ID can be used to position media items or other enrichments EnrichmentItem enrichmentItem = response.getEnrichmentItem(); String itemId = enrichmentItem.getId(); } catch (ApiException e) { // Handle error }
PHP
// Create the enrichment item using the PhotosLibraryResourceFactory helper $newEnrichmentItem = PhotosLibraryResourceFactory::newEnrichmentItemWithText(""); // ... // Set the position of the enrichment within the album $position = new AlbumPosition(); // ... try { // To add an enrichment, specify the album, the enrichment item, // and the position in the album where the enrichment is to be added $response = $photosLibraryClient->addEnrichmentToAlbum($albumId, $newEnrichmentItem, $position); // The response contains an EnrichmentItem // whose ID can be used to position media items or other enrichments $enrichmentItem = $response->getEnrichmentItem(); $itemId = $enrichmentItem->getId(); } catch (\Google\ApiCore\ApiException $e) { // Handle error }
支援的擴充功能
文字擴充
文字擴充包含單一文字字串 (不得超過 1000 個字元),例如 如以下範例所示:
REST
{ "text": "Text to be shown" }
Java
// Use the NewEnrichmentItemFactory helper to create a text enrichment item NewEnrichmentItem newEnrichmentItem = NewEnrichmentItemFactory.createTextEnrichment("text to be shown");
PHP
$newEnrichmentItem = PhotosLibraryResourceFactory::newEnrichmentItemWithText("text to be shown");
地點詳細資訊
地點擴充資料包含任意位置名稱、緯度和
經度位置。locationName
不得超過 500 個半形字元。
REST
{ "location": { "locationName": "Australia", "latlng": { "latitude": "-21.197", "longitude": "95.821" } } }
Java
// Use the NewEnrichmentItemFactory helper to create a location enrichment // with the name, latitude, and longitude of the location NewEnrichmentItem newEnrichmentItem = NewEnrichmentItemFactory.createLocationEnrichment("Australia", -21.197, 95.821);
PHP
// Create a new location object and set the name, latitude, and longitude of the location $newLocation = new Location(); $newLocation->setLocationName("Australia"); $newLocation->setLatlng((new LatLng())->setLatitude(-21.197)->setLongitude(95.821)); $newEnrichmentItem = PhotosLibraryResourceFactory::newEnrichmentItemWithLocation($newLocation);
地圖充實內容
地圖充實內容會顯示兩個地點,每個地點都含有名稱和緯度
和經度與位置擴充類似,中 locationName
來源,destination
不得超過 500 個字元。
REST
{ "origin": { "locationName": "Australia", "latlng": { "latitude": "-21.197", "longitude": "95.821" } }, "destination": { "locationName": "San Francisco", "latlng": { "latitude": "37.757", "longitude": "122.507" } } }
Java
// Use the NewEnrichmentItemFactory helper to create a map enrichment item for // an origin and a destination location NewEnrichmentItem newEnrichmentItem = NewEnrichmentItemFactory.createMapEnrichment( "Australia", -21.197, 95.821, // origin "San Francisco", 37.757, 122.507 // destination );
PHP
// Create two new location objects to create a map enrichment item // for an origin and a destination location $locationAustralia = new Location(); $locationAustralia->setLocationName("Australia"); $locationAustralia->setLatlng((new LatLng())->setLatitude(-21.197)->setLongitude(95.821)); $locationSanFrancisco = new Location(); $locationSanFrancisco->setLocationName("San Francisco"); $locationSanFrancisco->setLatlng((new LatLng())->setLatitude(37.757)->setLongitude(122.507)); $newEnrichmentItem = PhotosLibraryResourceFactory::newEnrichmentItemWithMap($locationAustralia, $locationSanFrancisco);
支援的定位
相簿開頭
位置 FIRST_IN_ALBUM
是指相簿開頭。找到的項目
使用者優先看到:
REST
{ "position": "FIRST_IN_ALBUM", }
Java
AlbumPosition albumPosition = AlbumPositionFactory.createFirstInAlbum();
PHP
$albumPosition = new AlbumPosition(); $albumPosition->setPosition(PositionType::FIRST_IN_ALBUM);
專輯結束時
位置 LAST_IN_ALBUM
是指相簿結尾。這裡的項目
使用者最後看到的名稱
REST
{ "position": "LAST_IN_ALBUM", }
Java
AlbumPosition albumPosition = AlbumPositionFactory.createLastInAlbum();
PHP
$albumPosition = new AlbumPosition(); $albumPosition->setPosition(PositionType::LAST_IN_ALBUM);
相對於媒體項目
指定 relativeMediaItem
的位置是指相對於
媒體項目。項目會接在指定的媒體項目後面。
REST
{ "position": "after-media-item", "relativeMediaItemId": "media-item-id" }
Java
AlbumPosition albumPosition = AlbumPositionFactory.createAfterMediaItem(mediaItemId);
PHP
$albumPosition = PhotosLibraryResourceFactory::albumPositionAfterMediaItem($mediaItemId);
相對於豐富項目
指定 relativeEnrichmentItemId
是指相對於
。項目會接在指定的擴充項目之後。
REST
{ "position": "after-enrichment-item", "relativeEnrichmentItemId": "enrichment-item-id" }
Java
AlbumPosition albumPosition = AlbumPositionFactory.createAfterEnrichmentItem(enrichmentItemId);
PHP
$albumPosition = PhotosLibraryResourceFactory::albumPositionAfterEnrichmentItem($enrichmentItemId);
修改擴充內容
目前無法修改擴充內容。不過,一旦經過擴充 建立完成並新增至相簿,使用者可以修改充實內容 透過 Google 相簿應用程式開啟相簿。