\Google\Photos\Library\V1\GapicPhotosLibraryGapicClient

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

Summary

Methods
Properties
Constants
__construct()
createAlbum()
batchCreateMediaItems()
searchMediaItems()
listMediaItems()
getMediaItem()
batchGetMediaItems()
listAlbums()
getAlbum()
getSharedAlbum()
addEnrichmentToAlbum()
joinSharedAlbum()
leaveSharedAlbum()
shareAlbum()
listSharedAlbums()
unshareAlbum()
$serviceScopes
SERVICE_NAME
SERVICE_ADDRESS
DEFAULT_SERVICE_PORT
CODEGEN_NAME
No protected methods found
No protected properties found
N/A
getClientDefaults()
No private properties found
N/A

Constants

SERVICE_NAME

SERVICE_NAME

The name of the service.

SERVICE_ADDRESS

SERVICE_ADDRESS

The default address of the service.

DEFAULT_SERVICE_PORT

DEFAULT_SERVICE_PORT

The default port of the service.

CODEGEN_NAME

CODEGEN_NAME

The name of the code generator, to be included in the agent header.

Properties

$serviceScopes

$serviceScopes : 

The default scopes required by the service.

Type

Methods

__construct()

__construct(array  $options = array()) 

Constructor.

Parameters

array $options

{ Optional. Options for configuring the service API wrapper.

@type string $serviceAddress
      The address of the API remote host. May optionally include the port, formatted
      as "<uri>:<port>". Default 'photoslibrary.googleapis.com:443'.
@type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials
      The credentials to be used by the client to authorize API calls. This option
      accepts either a path to a credentials file, or a decoded credentials file as a
      PHP array.
      *Advanced usage*: In addition, this option can also accept a pre-constructed
      {@see \Google\Auth\FetchAuthTokenInterface} object or
      {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these
      objects are provided, any settings in $credentialsConfig will be ignored.
@type array $credentialsConfig
      Options used to configure credentials, including auth token caching, for the client.
      For a full list of supporting configuration options, see
      {@see \Google\ApiCore\CredentialsWrapper::build()}.
@type bool $disableRetries
      Determines whether or not retries defined by the client configuration should be
      disabled. Defaults to `false`.
@type string|array $clientConfig
      Client method configuration, including retry settings. This option can be either a
      path to a JSON file, or a PHP array containing the decoded JSON data.
      By default this settings points to the default client config file, which is provided
      in the resources folder.
@type string|TransportInterface $transport
      The transport used for executing network requests. May be either the string `rest`
      or `grpc`. Defaults to `grpc` if gRPC support is detected on the system.
      *Advanced usage*: Additionally, it is possible to pass in an already instantiated
      {@see \Google\ApiCore\Transport\TransportInterface} object. Note that when this
      object is provided, any settings in $transportConfig, and any $serviceAddress
      setting, will be ignored.
@type array $transportConfig
      Configuration options that will be used to construct the transport. Options for
      each supported transport type should be passed in a key for that transport. For
      example:
      $transportConfig = [
          'grpc' => [...],
          'rest' => [...]
      ];
      See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and
      {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the
      supported options.

}

Throws

\Google\ApiCore\ValidationException

createAlbum()

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

Parameters

\Google\Photos\Library\V1\Album $album

The album to be created.

array $optionalArgs

{ Optional.

@type RetrySettings|array $retrySettings
     Retry settings to use for this call. Can be a
     {@see Google\ApiCore\RetrySettings} object, or an associative array
     of retry settings parameters. See the documentation on
     {@see Google\ApiCore\RetrySettings} for example usage.

}

Throws

\Google\ApiCore\ApiException

if the remote call fails

Returns

\Google\Photos\Library\V1\Album

batchCreateMediaItems()

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

Parameters

array<mixed,\Google\Photos\Library\V1\NewMediaItem> $newMediaItems

List of media items to be created.

array $optionalArgs

{ Optional.

@type string $albumId
     Identifier of the album where the media items are added. The media items
     are also added to the user's library. This is an optional field.
@type AlbumPosition $albumPosition
     Position in the album where the media items are added. If not
     specified, the media items are added to the end of the album (as per
     the default value, that is, `LAST_IN_ALBUM`). The request fails if this
     field is set and the `albumId` is not specified. The request will also fail
     if you set the field and are not the owner of the shared album.
@type RetrySettings|array $retrySettings
     Retry settings to use for this call. Can be a
     {@see Google\ApiCore\RetrySettings} object, or an associative array
     of retry settings parameters. See the documentation on
     {@see Google\ApiCore\RetrySettings} for example usage.

}

Throws

\Google\ApiCore\ApiException

if the remote call fails

Returns

\Google\Photos\Library\V1\BatchCreateMediaItemsResponse

searchMediaItems()

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

Parameters

array $optionalArgs

{ Optional.

@type string $albumId
     Identifier of an album. If populated, lists all media items in
     specified album. Can't set in conjunction with any filters.
@type int $pageSize
     The maximum number of resources contained in the underlying API
     response. The API may return fewer values in a page, even if
     there are additional values to be retrieved.
@type string $pageToken
     A page token is used to specify a page of values to be returned.
     If no page token is specified (the default), the first page
     of values will be returned. Any page token used here must have
     been generated by a previous call to the API.
@type Filters $filters
     Filters to apply to the request. Can't be set in conjunction with an
     `albumId`.
@type RetrySettings|array $retrySettings
     Retry settings to use for this call. Can be a
     {@see Google\ApiCore\RetrySettings} object, or an associative array
     of retry settings parameters. See the documentation on
     {@see Google\ApiCore\RetrySettings} for example usage.

}

Throws

\Google\ApiCore\ApiException

if the remote call fails

Returns

\Google\ApiCore\PagedListResponse

listMediaItems()

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

Parameters

array $optionalArgs

{ Optional.

@type int $pageSize
     The maximum number of resources contained in the underlying API
     response. The API may return fewer values in a page, even if
     there are additional values to be retrieved.
@type string $pageToken
     A page token is used to specify a page of values to be returned.
     If no page token is specified (the default), the first page
     of values will be returned. Any page token used here must have
     been generated by a previous call to the API.
@type RetrySettings|array $retrySettings
     Retry settings to use for this call. Can be a
     {@see Google\ApiCore\RetrySettings} object, or an associative array
     of retry settings parameters. See the documentation on
     {@see Google\ApiCore\RetrySettings} for example usage.

}

Throws

\Google\ApiCore\ApiException

if the remote call fails

Returns

\Google\ApiCore\PagedListResponse

getMediaItem()

getMediaItem(string  $mediaItemId, array  $optionalArgs = array()) : \Google\Photos\Library\V1\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();
}

Parameters

string $mediaItemId

Identifier of the media item to be requested.

array $optionalArgs

{ Optional.

@type RetrySettings|array $retrySettings
     Retry settings to use for this call. Can be a
     {@see Google\ApiCore\RetrySettings} object, or an associative array
     of retry settings parameters. See the documentation on
     {@see Google\ApiCore\RetrySettings} for example usage.

}

Throws

\Google\ApiCore\ApiException

if the remote call fails

Returns

\Google\Photos\Library\V1\MediaItem

batchGetMediaItems()

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

Parameters

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.

@type RetrySettings|array $retrySettings
     Retry settings to use for this call. Can be a
     {@see Google\ApiCore\RetrySettings} object, or an associative array
     of retry settings parameters. See the documentation on
     {@see Google\ApiCore\RetrySettings} for example usage.

}

Throws

\Google\ApiCore\ApiException

if the remote call fails

Returns

\Google\Photos\Library\V1\BatchGetMediaItemsResponse

listAlbums()

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

Parameters

array $optionalArgs

{ Optional.

@type int $pageSize
     The maximum number of resources contained in the underlying API
     response. The API may return fewer values in a page, even if
     there are additional values to be retrieved.
@type string $pageToken
     A page token is used to specify a page of values to be returned.
     If no page token is specified (the default), the first page
     of values will be returned. Any page token used here must have
     been generated by a previous call to the API.
@type bool $excludeNonAppCreatedData
     If set, the results exclude media items that were not created by this app.
     Defaults to false (all albums are returned). This field is ignored if the
     photoslibrary.readonly.appcreateddata scope is used.
@type RetrySettings|array $retrySettings
     Retry settings to use for this call. Can be a
     {@see Google\ApiCore\RetrySettings} object, or an associative array
     of retry settings parameters. See the documentation on
     {@see Google\ApiCore\RetrySettings} for example usage.

}

Throws

\Google\ApiCore\ApiException

if the remote call fails

Returns

\Google\ApiCore\PagedListResponse

getAlbum()

getAlbum(string  $albumId, array  $optionalArgs = array()) : \Google\Photos\Library\V1\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();
}

Parameters

string $albumId

Identifier of the album to be requested.

array $optionalArgs

{ Optional.

@type RetrySettings|array $retrySettings
     Retry settings to use for this call. Can be a
     {@see Google\ApiCore\RetrySettings} object, or an associative array
     of retry settings parameters. See the documentation on
     {@see Google\ApiCore\RetrySettings} for example usage.

}

Throws

\Google\ApiCore\ApiException

if the remote call fails

Returns

\Google\Photos\Library\V1\Album

getSharedAlbum()

getSharedAlbum(string  $shareToken, array  $optionalArgs = array()) : \Google\Photos\Library\V1\Album

Returns the album based on the specified `shareToken`.

Sample code:

$photosLibraryClient = new PhotosLibraryClient();
try {
    $shareToken = '';
    $response = $photosLibraryClient->getSharedAlbum($shareToken);
} finally {
    $photosLibraryClient->close();
}

Parameters

string $shareToken

Share token of the album to be requested.

array $optionalArgs

{ Optional.

@type RetrySettings|array $retrySettings
     Retry settings to use for this call. Can be a
     {@see Google\ApiCore\RetrySettings} object, or an associative array
     of retry settings parameters. See the documentation on
     {@see Google\ApiCore\RetrySettings} for example usage.

}

Throws

\Google\ApiCore\ApiException

if the remote call fails

Returns

\Google\Photos\Library\V1\Album

addEnrichmentToAlbum()

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

Parameters

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.

@type RetrySettings|array $retrySettings
     Retry settings to use for this call. Can be a
     {@see Google\ApiCore\RetrySettings} object, or an associative array
     of retry settings parameters. See the documentation on
     {@see Google\ApiCore\RetrySettings} for example usage.

}

Throws

\Google\ApiCore\ApiException

if the remote call fails

Returns

\Google\Photos\Library\V1\AddEnrichmentToAlbumResponse

joinSharedAlbum()

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

Parameters

string $shareToken

Token to join the shared album on behalf of the user.

array $optionalArgs

{ Optional.

@type RetrySettings|array $retrySettings
     Retry settings to use for this call. Can be a
     {@see Google\ApiCore\RetrySettings} object, or an associative array
     of retry settings parameters. See the documentation on
     {@see Google\ApiCore\RetrySettings} for example usage.

}

Throws

\Google\ApiCore\ApiException

if the remote call fails

Returns

\Google\Photos\Library\V1\JoinSharedAlbumResponse

leaveSharedAlbum()

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

Parameters

string $shareToken

Token to leave the shared album on behalf of the user.

array $optionalArgs

{ Optional.

@type RetrySettings|array $retrySettings
     Retry settings to use for this call. Can be a
     {@see Google\ApiCore\RetrySettings} object, or an associative array
     of retry settings parameters. See the documentation on
     {@see Google\ApiCore\RetrySettings} for example usage.

}

Throws

\Google\ApiCore\ApiException

if the remote call fails

Returns

\Google\Photos\Library\V1\LeaveSharedAlbumResponse

shareAlbum()

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

Parameters

string $albumId

Identifier of the album to be shared. This albumId must belong to an album created by the developer.

array $optionalArgs

{ Optional.

@type SharedAlbumOptions $sharedAlbumOptions
     Options to be set when converting the album to a shared album.
@type RetrySettings|array $retrySettings
     Retry settings to use for this call. Can be a
     {@see Google\ApiCore\RetrySettings} object, or an associative array
     of retry settings parameters. See the documentation on
     {@see Google\ApiCore\RetrySettings} for example usage.

}

Throws

\Google\ApiCore\ApiException

if the remote call fails

Returns

\Google\Photos\Library\V1\ShareAlbumResponse

listSharedAlbums()

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

Parameters

array $optionalArgs

{ Optional.

@type int $pageSize
     The maximum number of resources contained in the underlying API
     response. The API may return fewer values in a page, even if
     there are additional values to be retrieved.
@type string $pageToken
     A page token is used to specify a page of values to be returned.
     If no page token is specified (the default), the first page
     of values will be returned. Any page token used here must have
     been generated by a previous call to the API.
@type bool $excludeNonAppCreatedData
     If set, the results exclude media items that were not created by this app.
     Defaults to false (all albums are returned). This field is ignored if the
     photoslibrary.readonly.appcreateddata scope is used.
@type RetrySettings|array $retrySettings
     Retry settings to use for this call. Can be a
     {@see Google\ApiCore\RetrySettings} object, or an associative array
     of retry settings parameters. See the documentation on
     {@see Google\ApiCore\RetrySettings} for example usage.

}

Throws

\Google\ApiCore\ApiException

if the remote call fails

Returns

\Google\ApiCore\PagedListResponse

unshareAlbum()

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

Parameters

string $albumId

Identifier of the album to be unshared. This album id must belong to an album created by the developer.

array $optionalArgs

{ Optional.

@type RetrySettings|array $retrySettings
     Retry settings to use for this call. Can be a
     {@see Google\ApiCore\RetrySettings} object, or an associative array
     of retry settings parameters. See the documentation on
     {@see Google\ApiCore\RetrySettings} for example usage.

}

Throws

\Google\ApiCore\ApiException

if the remote call fails

Returns

\Google\Photos\Library\V1\UnshareAlbumResponse

getClientDefaults()

getClientDefaults()