SERVICE_NAME
SERVICE_NAME
The name of the service.
Service Description: Service which allows developers to perform the following actions on behalf of the user: - upload media items directly to their Google Photos library - create albums - add media items (including album enrichments) to albums - list and download content from their Google Photos library - filter results by media type, date range or content category - create, join, and access shared albums.
This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
$photosLibraryClient = new PhotosLibraryClient();
try {
$album = new Album();
$response = $photosLibraryClient->createAlbum($album);
} finally {
$photosLibraryClient->close();
}
__construct(array $options = array())
Constructor.
array | $options | { Optional. Options for configuring the service API wrapper.
} |
createAlbum(\Google\Photos\Library\V1\Album $album, array $optionalArgs = array()) : \Google\Photos\Library\V1\Album
Creates an album in a user's Google Photos library.
Sample code:
$photosLibraryClient = new PhotosLibraryClient();
try {
$album = new Album();
$response = $photosLibraryClient->createAlbum($album);
} finally {
$photosLibraryClient->close();
}
\Google\Photos\Library\V1\Album | $album | The album to be created. |
array | $optionalArgs | { Optional.
} |
if the remote call fails
batchCreateMediaItems(array<mixed,\Google\Photos\Library\V1\NewMediaItem> $newMediaItems, array $optionalArgs = array()) : \Google\Photos\Library\V1\BatchCreateMediaItemsResponse
Creates one or more media items in a user's Google Photos library.
This is the second step for creating a media item. For details regarding Step 1, uploading the raw bytes to a Google Server, see Uploading media.
This call adds the media item to the library. If an album id
is
specified, the call adds the media item to the album too. By default, the
media item will be added to the end of the library or album.
If an album id
and position are both defined, the media item is
added to the album at the specified position.
If the call contains multiple media items, they're added at the specified
position.
If you are creating a media item in a shared album where you are not the
owner, you are not allowed to position the media item. Doing so will result
in a BAD REQUEST
error.
Sample code:
$photosLibraryClient = new PhotosLibraryClient();
try {
$newMediaItems = [];
$response = $photosLibraryClient->batchCreateMediaItems($newMediaItems);
} finally {
$photosLibraryClient->close();
}
array<mixed,\Google\Photos\Library\V1\NewMediaItem> | $newMediaItems | List of media items to be created. |
array | $optionalArgs | { Optional.
} |
if the remote call fails
searchMediaItems(array $optionalArgs = array()) : \Google\ApiCore\PagedListResponse
Searches for media items in a user's Google Photos library.
If no filters are set, then all media items in the user's library are returned. If an album is set, all media items in the specified album are returned. If filters are specified, media items that match the filters from the user's library are listed. If you set both the album and the filters, the request results in an error.
Sample code:
$photosLibraryClient = new PhotosLibraryClient();
try {
// Iterate over pages of elements
$pagedResponse = $photosLibraryClient->searchMediaItems();
foreach ($pagedResponse->iteratePages() as $page) {
foreach ($page as $element) {
// doSomethingWith($element);
}
}
// Alternatively:
// Iterate through all elements
$pagedResponse = $photosLibraryClient->searchMediaItems();
foreach ($pagedResponse->iterateAllElements() as $element) {
// doSomethingWith($element);
}
} finally {
$photosLibraryClient->close();
}
array | $optionalArgs | { Optional.
} |
if the remote call fails
listMediaItems(array $optionalArgs = array()) : \Google\ApiCore\PagedListResponse
List all media items from a user's Google Photos library.
Sample code:
$photosLibraryClient = new PhotosLibraryClient();
try {
// Iterate over pages of elements
$pagedResponse = $photosLibraryClient->listMediaItems();
foreach ($pagedResponse->iteratePages() as $page) {
foreach ($page as $element) {
// doSomethingWith($element);
}
}
// Alternatively:
// Iterate through all elements
$pagedResponse = $photosLibraryClient->listMediaItems();
foreach ($pagedResponse->iterateAllElements() as $element) {
// doSomethingWith($element);
}
} finally {
$photosLibraryClient->close();
}
array | $optionalArgs | { Optional.
} |
if the remote call fails
getMediaItem(string $mediaItemId, array $optionalArgs = array()) : \Google\Photos\Library\V1\MediaItem
Returns the media item for the specified media item `id`.
Sample code:
$photosLibraryClient = new PhotosLibraryClient();
try {
$mediaItemId = '';
$response = $photosLibraryClient->getMediaItem($mediaItemId);
} finally {
$photosLibraryClient->close();
}
string | $mediaItemId | Identifier of media item to be requested. |
array | $optionalArgs | { Optional.
} |
if the remote call fails
listAlbums(array $optionalArgs = array()) : \Google\ApiCore\PagedListResponse
Lists all albums shown to a user in the Albums tab of the Google Photos app.
Sample code:
$photosLibraryClient = new PhotosLibraryClient();
try {
// Iterate over pages of elements
$pagedResponse = $photosLibraryClient->listAlbums();
foreach ($pagedResponse->iteratePages() as $page) {
foreach ($page as $element) {
// doSomethingWith($element);
}
}
// Alternatively:
// Iterate through all elements
$pagedResponse = $photosLibraryClient->listAlbums();
foreach ($pagedResponse->iterateAllElements() as $element) {
// doSomethingWith($element);
}
} finally {
$photosLibraryClient->close();
}
array | $optionalArgs | { Optional.
} |
if the remote call fails
getAlbum(string $albumId, array $optionalArgs = array()) : \Google\Photos\Library\V1\Album
Returns the album based on the specified `albumId` or `shareToken`.
Exactly one of albumId
and shareToken
must be set.
The albumId
should be the ID of an album owned by the user or a shared
album that the user has joined.
Sample code:
$photosLibraryClient = new PhotosLibraryClient();
try {
$albumId = '';
$response = $photosLibraryClient->getAlbum($albumId);
} finally {
$photosLibraryClient->close();
}
string | $albumId | Identifier of the album to be requested. Must not be set if |
array | $optionalArgs | { Optional.
} |
if the remote call fails
addEnrichmentToAlbum(string $albumId, \Google\Photos\Library\V1\NewEnrichmentItem $newEnrichmentItem, \Google\Photos\Library\V1\AlbumPosition $albumPosition, array $optionalArgs = array()) : \Google\Photos\Library\V1\AddEnrichmentToAlbumResponse
Adds an enrichment at a specified position in a defined album.
Sample code:
$photosLibraryClient = new PhotosLibraryClient();
try {
$albumId = '';
$newEnrichmentItem = new NewEnrichmentItem();
$albumPosition = new AlbumPosition();
$response = $photosLibraryClient->addEnrichmentToAlbum($albumId, $newEnrichmentItem, $albumPosition);
} finally {
$photosLibraryClient->close();
}
string | $albumId | Identifier of the album where the enrichment is to be added. |
\Google\Photos\Library\V1\NewEnrichmentItem | $newEnrichmentItem | The enrichment to be added. |
\Google\Photos\Library\V1\AlbumPosition | $albumPosition | The position in the album where the enrichment is to be inserted. |
array | $optionalArgs | { Optional.
} |
if the remote call fails
joinSharedAlbum(string $shareToken, array $optionalArgs = array()) : \Google\Photos\Library\V1\JoinSharedAlbumResponse
Joins a shared album on behalf of the Google Photos user.
Sample code:
$photosLibraryClient = new PhotosLibraryClient();
try {
$shareToken = '';
$response = $photosLibraryClient->joinSharedAlbum($shareToken);
} finally {
$photosLibraryClient->close();
}
string | $shareToken | Token to join the shared album on behalf of the user. |
array | $optionalArgs | { Optional.
} |
if the remote call fails
shareAlbum(string $albumId, array $optionalArgs = array()) : \Google\Photos\Library\V1\ShareAlbumResponse
Marks an album as shared and accessible to other users. This action can only be performed on albums which were created by the developer via the API.
Sample code:
$photosLibraryClient = new PhotosLibraryClient();
try {
$albumId = '';
$response = $photosLibraryClient->shareAlbum($albumId);
} finally {
$photosLibraryClient->close();
}
string | $albumId | Identifier of the album to be shared. This |
array | $optionalArgs | { Optional.
} |
if the remote call fails
listSharedAlbums(array $optionalArgs = array()) : \Google\ApiCore\PagedListResponse
Lists all shared albums available in the Sharing tab of the user's Google Photos app.
Sample code:
$photosLibraryClient = new PhotosLibraryClient();
try {
// Iterate over pages of elements
$pagedResponse = $photosLibraryClient->listSharedAlbums();
foreach ($pagedResponse->iteratePages() as $page) {
foreach ($page as $element) {
// doSomethingWith($element);
}
}
// Alternatively:
// Iterate through all elements
$pagedResponse = $photosLibraryClient->listSharedAlbums();
foreach ($pagedResponse->iterateAllElements() as $element) {
// doSomethingWith($element);
}
} finally {
$photosLibraryClient->close();
}
array | $optionalArgs | { Optional.
} |
if the remote call fails