Ajouter des informations enrichies

Les fonctionnalités d'enrichissement permettent à votre application de contrôler la structure et la présentation les photos d'un album Google Photos. Elles vous permettent de présenter à l'utilisateur avec du contexte supplémentaire par le biais d'annotations de texte ou de lieu, et de l'ordre/du groupe des images qui racontent une histoire ensemble.

Champ d'application de l'autorisation requis

Pour ajouter des fonctionnalités, vous devez spécifier au moins l'un des champs d'application suivants:

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

Pour chaque niveau d'accès, l'appel enrichAlbum est limité aux albums créés par l'application.

Lorsque vous utilisez le champ d'application .sharing, enrichAlbum est limité à certaines circonstances lorsque le développeur agit au nom du propriétaire de l'album partagé.

Types d'enrichissements

Google Photos propose trois types d'enrichissements: texte, des lieux et des cartes.

Enrichissements de texte

Une "enrichissement de texte" est une chaîne de texte brut qui peut être insérée pour annoter le album.

Capture d'écran d'une fonctionnalité d'enrichissement de texte affichée dans Google Photos

Enrichissements des données de localisation

Une option d'enrichissement de la position est un repère et le nom du lieu qui peut être inséré pour annoter un lieu.

Capture d'écran d'une fonctionnalité d'enrichissement des lieux dans Google Photos

Enrichissements des cartes

Une carte enrichie est une carte dont le point de départ et la destination spécifiés inséré dans l'album.

Capture d'écran d'une carte enrichie dans Google Photos

Positions

Pour insérer des éléments multimédias et des éléments d'enrichissement d'albums, spécifiez la position de l'album. La position est facultative pour les éléments multimédias, mais elle doit être spécifiée pour l'album. ou d'enrichissement.

Une position ne peut être spécifiée que lorsque créer un élément multimédia ou d'enrichissements. Les éléments multimédias existants d'un album ne peuvent pas être réorganisés. Par conséquent, il est important de définir la position d'un élément lors de son ajout.

Début de l'album

Un élément multimédia ou enrichit peut être ajouté au début de l'album en tant qu'élément multimédia absolu de votre application.

Fin de l'album

Un élément multimédia ou enrichit peut être ajouté à la fin de l'album de façon absolue. de votre application.

Par rapport à l'élément multimédia

Un élément multimédia ou d'enrichissement peut être ajouté par rapport à un élément multimédia commençant après le sa position dans l'album.

Par rapport à l'élément d'enrichissement

Un élément multimédia/d'enrichissement peut être ajouté par rapport au début d'un élément d'enrichissement après sa position dans l'album.

Ajout d'enrichissements à un album...

Les enrichissements sont ajoutés un par un et doivent être ajoutés à une position dans un album. Pour enrichir un album, appelez albums.addEnrichment

Si la requête aboutit, le id de l'élément d'enrichissement est renvoyé, pour positionner des éléments multimédias ou d'autres éléments d'enrichissement.

REST

Voici une requête POST:

POST https://photoslibrary.googleapis.com/v1/albums/album-id:addEnrichment
Content-type: application/json
Authorization: Bearer oauth2-token
request-body

Le corps de la requête comprend l'élément d'enrichissement et sa position:

{
  "newEnrichmentItem": {
    enrichment-to-be-added
  },
  "albumPosition": {
    position-of-enrichment
}

Voici un exemple de réponse :

{
  "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
}

Enrichissements compatibles

Enrichissements de texte

Les enrichissements de texte contiennent une seule chaîne de texte (1 000 caractères maximum), car illustré dans l'exemple suivant:

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");

Enrichissements des données de localisation

L'enrichissement des données de localisation se compose d'un nom de lieu arbitraire, ainsi que des coordonnées de latitude et et sa longitude. Le champ locationName est limité à 500 caractères.

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);

Enrichissements des cartes

Les éléments enrichis de carte montrent deux lieux, chacun constitué d'un nom et d'une latitude et la longitude. Comme pour l'enrichissement des données de localisation, le locationName dans le origine et destination est limité à 500 caractères.

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);

Positionnement compatible

Début de l'album

La position FIRST_IN_ALBUM fait référence au début de l'album. Articles localisés sont présentées à l'utilisateur en premier:

REST

{
  "position": "FIRST_IN_ALBUM",
}

Java

AlbumPosition albumPosition = AlbumPositionFactory.createFirstInAlbum();

PHP

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

Fin de l'album

La position LAST_IN_ALBUM fait référence à la fin de l'album. Articles situés ici sont présentées à l'utilisateur en dernier.

REST

{
  "position": "LAST_IN_ALBUM",
}

Java

AlbumPosition albumPosition = AlbumPositionFactory.createLastInAlbum();

PHP

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

Par rapport à l'élément multimédia

Le fait de spécifier la position relativeMediaItem fait référence à une position par rapport à élément multimédia. Les éléments sont ajoutés après l'élément multimédia spécifié.

REST

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

Java

AlbumPosition albumPosition = AlbumPositionFactory.createAfterMediaItem(mediaItemId);

PHP

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

Par rapport à l'élément d'enrichissement

La spécification d'un relativeEnrichmentItemId fait référence à une position par rapport à un élément d'enrichissement. Les éléments sont ajoutés après l'élément d'enrichissement spécifié.

REST

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

Java

AlbumPosition albumPosition = AlbumPositionFactory.createAfterEnrichmentItem(enrichmentItemId);

PHP

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

Modifier les options d'enrichissement

Il n'existe actuellement aucun moyen de modifier les options d'enrichissement. Cependant, une fois qu'une source d'enrichissement a été créé et ajouté à un album, l'utilisateur peut modifier les options d'enrichissement via l'application Google Photos.