غنی سازی ها را اضافه کنید

غنی‌سازی‌ها به برنامه شما اجازه می‌دهند ساختار و نمایش عکس‌ها را در یک آلبوم در Google Photos کنترل کند. آنها به شما این امکان را می دهند که از طریق متن یا حاشیه نویسی مکان و سفارش/گروه بندی تصاویری که داستانی را با هم روایت می کنند، زمینه اضافی را به کاربر ارائه دهید.

محدوده مجوز مورد نیاز

برای افزودن غنی‌سازی‌ها، حداقل یکی از حوزه‌های زیر مورد نیاز است:

  • photoslibrary.appendonly
  • photoslibrary.library
  • photoslibrary.sharing

برای هر محدوده، تماس enrichAlbum فقط به آلبوم‌های ایجاد شده توسط برنامه محدود می‌شود.

هنگام استفاده از محدوده .sharing ، enrichAlbum محدود به شرایطی است که توسعه‌دهنده از طرف مالک آلبوم مشترک عمل می‌کند.

انواع غنی سازی

Google Photos از سه نوع غنی‌سازی در آلبوم‌ها پشتیبانی می‌کند: متن، مکان‌ها و نقشه‌ها.

غنی سازی متن

غنی سازی متن یک رشته متن ساده است که می تواند برای حاشیه نویسی آلبوم درج شود.

اسکرین شات غنی سازی متن نشان داده شده در Google Photos

غنی سازی مکان

غنی‌سازی مکان یک نشانگر و نام مکانی است که می‌تواند برای حاشیه‌نویسی یک مکان درج شود.

نماگرفت غنی‌سازی موقعیت مکانی نشان داده شده در Google Photos

غنی سازی نقشه

غنی سازی نقشه نقشه ای است با مبدأ و مقصد مشخص که می تواند در آلبوم درج شود.

تصویری از غنی‌سازی نقشه که در Google Photos نشان داده شده است

موقعیت ها

برای درج موارد رسانه و غنی‌سازی آلبوم، موقعیت آلبوم را مشخص کنید. یک موقعیت برای آیتم های رسانه اختیاری است، اما باید برای غنی سازی آلبوم مشخص شود.

یک موقعیت را فقط می توان در هنگام ایجاد یک آیتم رسانه ای یا افزودن موارد غنی سازی مشخص کرد. آیتم‌های رسانه‌ای موجود در آلبوم را نمی‌توان سازمان‌دهی مجدد کرد، بنابراین تنظیم موقعیت یک مورد هنگام افزودن آن بسیار مهم است.

شروع آلبوم

یک آیتم رسانه ای/غنی کننده را می توان به عنوان موقعیت یابی مطلق به ابتدای آلبوم اضافه کرد.

پایان آلبوم

یک آیتم رسانه ای/غنی کننده را می توان به عنوان موقعیت یابی مطلق به انتهای آلبوم اضافه کرد.

نسبت به آیتم رسانه ای

یک آیتم رسانه/غنی کننده را می توان نسبت به یک آیتم رسانه ای که بعد از موقعیت آن در آلبوم شروع می شود، اضافه کرد.

نسبت به مورد غنی سازی

یک آیتم رسانه / غنی‌سازی را می‌توان نسبت به یک آیتم غنی‌سازی که بعد از موقعیت آن در آلبوم شروع می‌شود، اضافه کرد.

افزودن مواد غنی شده به آلبوم

غنی‌سازی‌ها یکی یکی اضافه می‌شوند و باید به موقعیتی در آلبوم اضافه شوند. برای افزودن غنی‌سازی به آلبوم، با albums.addEnrichment تماس بگیرید.

اگر درخواست موفقیت آمیز باشد، id مورد غنی‌سازی را برمی‌گرداند که می‌توان از آن برای موقعیت‌یابی آیتم‌های رسانه یا سایر غنی‌سازی‌ها استفاده کرد.

باقی مانده

در اینجا یک درخواست 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",
  }
}

جاوا

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 کاراکتر):

باقی مانده

{
  "text": "Text to be shown"
}

جاوا

// 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 کاراکتر محدود شده است.

باقی مانده

{
  "location": {
    "locationName": "Australia",
    "latlng": {
      "latitude": "-21.197",
      "longitude": "95.821"
    }
  }
}

جاوا

// 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 کاراکتر محدود می‌شود.

باقی مانده

{
  "origin": {
    "locationName": "Australia",
    "latlng": {
      "latitude": "-21.197",
      "longitude": "95.821"
    }
  },
  "destination": {
    "locationName": "San Francisco",
    "latlng": {
      "latitude": "37.757",
      "longitude": "122.507"
    }
  }
}

جاوا

// 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 به شروع آلبوم اشاره دارد. مواردی که در اینجا قرار دارند ابتدا به کاربر نشان داده می شوند:

باقی مانده

{
  "position": "FIRST_IN_ALBUM",
}

جاوا

AlbumPosition albumPosition = AlbumPositionFactory.createFirstInAlbum();

PHP

$albumPosition = new AlbumPosition();
$albumPosition->setPosition(PositionType::FIRST_IN_ALBUM);

پایان آلبوم

موقعیت LAST_IN_ALBUM به انتهای آلبوم اشاره دارد. مواردی که در اینجا قرار دارند آخرین بار به کاربر نشان داده می شوند.

باقی مانده

{
  "position": "LAST_IN_ALBUM",
}

جاوا

AlbumPosition albumPosition = AlbumPositionFactory.createLastInAlbum();

PHP

$albumPosition = new AlbumPosition();
$albumPosition->setPosition(PositionType::LAST_IN_ALBUM);

نسبت به آیتم رسانه ای

تعیین موقعیت relativeMediaItem به موقعیتی نسبت به یک آیتم رسانه اشاره دارد. موارد بعد از آیتم رسانه ای مشخص شده اضافه می شوند.

باقی مانده

{
  "position": "after-media-item",
  "relativeMediaItemId": "media-item-id"
}

جاوا

AlbumPosition albumPosition = AlbumPositionFactory.createAfterMediaItem(mediaItemId);

PHP

$albumPosition = PhotosLibraryResourceFactory::albumPositionAfterMediaItem($mediaItemId);

نسبت به مورد غنی سازی

تعیین یک relativeEnrichmentItemId به موقعیتی نسبت به یک آیتم غنی شده اشاره دارد. موارد بعد از آیتم غنی سازی مشخص شده اضافه می شوند.

باقی مانده

{
  "position": "after-enrichment-item",
  "relativeEnrichmentItemId": "enrichment-item-id"
}

جاوا

AlbumPosition albumPosition = AlbumPositionFactory.createAfterEnrichmentItem(enrichmentItemId);

PHP

$albumPosition = PhotosLibraryResourceFactory::albumPositionAfterEnrichmentItem($enrichmentItemId);

اصلاح غنی سازی ها

در حال حاضر هیچ راهی برای اصلاح غنی سازی وجود ندارد. با این حال، هنگامی که یک غنی‌سازی ایجاد شد و به آلبوم اضافه شد، کاربر می‌تواند از طریق برنامه Google Photos غنی‌سازی‌ها را تغییر دهد.