SERVICE_NAME
SERVICE_NAME = 'google.photos.library.v1.PhotosLibrary'
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\Types\Album $album, array $optionalArgs = array()) : \Google\Photos\Types\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\Types\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. Each album can
contain up to 20,000 media items. 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
batchAddMediaItemsToAlbum(string $albumId, array<mixed,string> $mediaItemIds, array $optionalArgs = array()) : \Google\Photos\Library\V1\BatchAddMediaItemsToAlbumResponse
Adds one or more media items in a user's Google Photos library to an album. The media items and albums must have been created by the developer via the API.
Media items are added to the end of the album. If multiple media items are given, they are added in the order specified in this call.
Each album can contain up to 20,000 media items.
Only media items that are in the user's library can be added to an album. For albums that are shared, the album must either be owned by the user or the user must have joined the album as a collaborator.
Partial success is not supported. The entire request will fail if an invalid media item or album is specified.
Sample code:
$photosLibraryClient = new PhotosLibraryClient();
try {
$albumId = '';
$mediaItemIds = [];
$response = $photosLibraryClient->batchAddMediaItemsToAlbum($albumId, $mediaItemIds);
} finally {
$photosLibraryClient->close();
}
string | $albumId | Identifier of the [Album][google.photos.types.Album] that the media items are added to. |
array<mixed,string> | $mediaItemIds | Identifiers of the [MediaItem][google.photos.types.MediaItem]s to be added. The maximum number of media items that can be added in one call is 50. |
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\Types\MediaItem
Returns the media item for the specified media item identifier.
Sample code:
$photosLibraryClient = new PhotosLibraryClient();
try {
$mediaItemId = '';
$response = $photosLibraryClient->getMediaItem($mediaItemId);
} finally {
$photosLibraryClient->close();
}
string | $mediaItemId | Identifier of the media item to be requested. |
array | $optionalArgs | { Optional.
} |
if the remote call fails
batchGetMediaItems(array<mixed,string> $mediaItemIds, array $optionalArgs = array()) : \Google\Photos\Library\V1\BatchGetMediaItemsResponse
Returns the list of media items for the specified media item identifiers.
Items are returned in the same order as the supplied identifiers.
Sample code:
$photosLibraryClient = new PhotosLibraryClient();
try {
$mediaItemIds = [];
$response = $photosLibraryClient->batchGetMediaItems($mediaItemIds);
} finally {
$photosLibraryClient->close();
}
array<mixed,string> | $mediaItemIds | Identifiers of the media items to be requested. Must not contain repeated identifiers and cannot be empty. The maximum number of media items that can be retrieved in one call is 50. |
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\Types\Album
Returns the album based on the specified `albumId`.
The albumId
must 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. |
array | $optionalArgs | { Optional.
} |
if the remote call fails
getSharedAlbum(string $shareToken, array $optionalArgs = array()) : \Google\Photos\Types\Album
Returns the album based on the specified `shareToken`.
Sample code:
$photosLibraryClient = new PhotosLibraryClient();
try {
$shareToken = '';
$response = $photosLibraryClient->getSharedAlbum($shareToken);
} finally {
$photosLibraryClient->close();
}
string | $shareToken | Share token of the album to be requested. |
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
leaveSharedAlbum(string $shareToken, array $optionalArgs = array()) : \Google\Photos\Library\V1\LeaveSharedAlbumResponse
Leaves a previously-joined shared album on behalf of the Google Photos user. The user must not own this album.
Sample code:
$photosLibraryClient = new PhotosLibraryClient();
try {
$shareToken = '';
$response = $photosLibraryClient->leaveSharedAlbum($shareToken);
} finally {
$photosLibraryClient->close();
}
string | $shareToken | Token to leave 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
unshareAlbum(string $albumId, array $optionalArgs = array()) : \Google\Photos\Library\V1\UnshareAlbumResponse
Marks a previously shared album as private. This means that the album is no longer shared and all the non-owners will lose access to the album. All non-owner content will be removed from the album. If a non-owner has previously added the album to their library, they will retain all photos in their library. 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->unshareAlbum($albumId);
} finally {
$photosLibraryClient->close();
}
string | $albumId | Identifier of the album to be unshared. This album id must belong to an album created by the developer. |
array | $optionalArgs | { Optional.
} |
if the remote call fails
batchRemoveMediaItemsFromAlbum(string $albumId, array<mixed,string> $mediaItemIds, array $optionalArgs = array()) : \Google\Photos\Library\V1\BatchRemoveMediaItemsFromAlbumResponse
Removes one or more media items from a specified album. The media items and the album must have been created by the developer via the API.
For albums that are shared, this action is only supported for media items that were added to the album by this user, or for all media items if the album was created by this user.
Partial success is not supported. The entire request will fail and no action will be performed on the album if an invalid media item or album is specified.
Sample code:
$photosLibraryClient = new PhotosLibraryClient();
try {
$albumId = '';
$mediaItemIds = [];
$response = $photosLibraryClient->batchRemoveMediaItemsFromAlbum($albumId, $mediaItemIds);
} finally {
$photosLibraryClient->close();
}
string | $albumId | Identifier of the [Album][google.photos.types.Album] that the media items are to be removed from. |
array<mixed,string> | $mediaItemIds | Identifiers of the [MediaItem][google.photos.types.MediaItem]s to be removed. Must not contain repeated identifiers and cannot be empty. The maximum number of media items that can be removed in one call is 50. |
array | $optionalArgs | { Optional.
} |
if the remote call fails
updateAlbum(\Google\Photos\Types\Album $album, \Google\Protobuf\FieldMask $updateMask, array $optionalArgs = array()) : \Google\Photos\Types\Album
Update the album with the specified `id`.
Only the id
, title
and cover_photo_media_item_id
fields of the album
are read. The album must have been created by the developer via the API and
must be owned by the user.
Sample code:
$photosLibraryClient = new PhotosLibraryClient();
try {
$album = new Album();
$updateMask = new FieldMask();
$response = $photosLibraryClient->updateAlbum($album, $updateMask);
} finally {
$photosLibraryClient->close();
}
\Google\Photos\Types\Album | $album | Required. The [Album][google.photos.types.Album] to update. The album’s |
\Google\Protobuf\FieldMask | $updateMask | Indicate what fields in the provided album to update.
The only valid values are |
array | $optionalArgs | { Optional.
} |
if the remote call fails
updateMediaItem(\Google\Photos\Types\MediaItem $mediaItem, \Google\Protobuf\FieldMask $updateMask, array $optionalArgs = array()) : \Google\Photos\Types\MediaItem
Update the media item with the specified `id`.
Only the id
and description
fields of the media item are read. The
media item must have been created by the developer via the API and must be
owned by the user.
Sample code:
$photosLibraryClient = new PhotosLibraryClient();
try {
$mediaItem = new MediaItem();
$updateMask = new FieldMask();
$response = $photosLibraryClient->updateMediaItem($mediaItem, $updateMask);
} finally {
$photosLibraryClient->close();
}
\Google\Photos\Types\MediaItem | $mediaItem | Required. The [MediaItem][google.photos.types.MediaItem] to update. The media item's |
\Google\Protobuf\FieldMask | $updateMask | Indicate what fields in the provided media item to update.
The only valid value is |
array | $optionalArgs | { Optional.
} |
if the remote call fails
upload(string $rawFile, string $fileName = '', string $mimeType = '') : string
Uploads a media item to Google. This won't create a media item in the user's Google Photos library.
string | $rawFile | The raw bytes of the file, obtained by something like file_get_contents(). |
string | $fileName | The name of the file to be uploaded. This is no longer recommended Filenames should be set in the batchCreate call instead. |
string | $mimeType | The MIME type of the file to be uploaded. For example, text/html. |
An upload token
updateAlbumTitle(string $albumId, string $newTitle, array $optionalArgs = array()) : \Google\Photos\Types\Album
Updates the album with a new title.
The album must have been created by the developer via the API and must be owned by the user.
string | $albumId | Identifier of the [Album][google.photos.types.Album] to update |
string | $newTitle | Required. The new title of the album. |
array | $optionalArgs |
if the remote call fails
updateAlbumCoverPhoto(string $albumId, string $newCoverMediaItemId, array $optionalArgs = array()) : \Google\Photos\Types\Album
Updates the album with a new cover photo.
The album must have been created by the developer via the API and must be owned by the user.
The $newCoverMediaItemId must be the identifier of a media item contained within the album.
string | $albumId | Identifier of the [Album][google.photos.types.Album] to update |
string | $newCoverMediaItemId | Required. The identifier of the new media item cover photo. |
array | $optionalArgs |
if the remote call fails
updateMediaItemDescription(string $mediaItemId, string $newDescription, array $optionalArgs = array()) : \Google\Photos\Types\MediaItem
Updates the media item with a new description.
The media item must have been created by the developer via the API and must be owned by the user.
string | $mediaItemId | Required. Identifier of the [MediaItem][google.photos.types.MediaItem] to update. |
string | $newDescription | The new description for the media item. |
array | $optionalArgs |
if the remote call fails
contentCategories()
Warning: count(): Parameter must be an array or an object that implements Countable in phar:///Users/jfschmakeit/Downloads/phpDocumentor (2).phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275 Warning: count(): Parameter must be an array or an object that implements Countable in phar:///Users/jfschmakeit/Downloads/phpDocumentor (2).phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275
mediaTypes()
Warning: count(): Parameter must be an array or an object that implements Countable in phar:///Users/jfschmakeit/Downloads/phpDocumentor (2).phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275 Warning: count(): Parameter must be an array or an object that implements Countable in phar:///Users/jfschmakeit/Downloads/phpDocumentor (2).phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275
features()
Warning: count(): Parameter must be an array or an object that implements Countable in phar:///Users/jfschmakeit/Downloads/phpDocumentor (2).phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275 Warning: count(): Parameter must be an array or an object that implements Countable in phar:///Users/jfschmakeit/Downloads/phpDocumentor (2).phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275
getClientDefaults()
Warning: count(): Parameter must be an array or an object that implements Countable in phar:///Users/jfschmakeit/Downloads/phpDocumentor (2).phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275 Warning: count(): Parameter must be an array or an object that implements Countable in phar:///Users/jfschmakeit/Downloads/phpDocumentor (2).phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275
retryDecider(\Google\Photos\Library\V1\UploadRetrySettings $uploadRetrySettings) : \Closure
Returns a function that determines if a given request should be retried.
The returned function returns true if the status was not okay, the error was in one of the acceptable retry codes, and the maximum number of retries has not been exceeded.
\Google\Photos\Library\V1\UploadRetrySettings | $uploadRetrySettings |
retryDelay(\Google\Photos\Library\V1\UploadRetrySettings $uploadRetrySettings) : \Closure
Returns a function that determines the delay before a request is retried.
Implements exponential backoff, with some maximum delay.
\Google\Photos\Library\V1\UploadRetrySettings | $uploadRetrySettings |