PHP code example of google / photos-library

1. Go to this page and download the library: Download google/photos-library library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

google / photos-library example snippets


// [START sample_usage]
use Google\Auth\Credentials\UserRefreshCredentials;
use Google\Photos\Library\V1\PhotosLibraryClient;
use Google\Photos\Library\V1\PhotosLibraryResourceFactory;

try {
    // Use the OAuth flow provided by the Google API Client Auth library
    // to authenticate users. See the file /src/common/common.php in the samples for a complete
    // authentication example.
    $authCredentials = new UserRefreshCredentials( /* Add your scope, client secret and refresh token here */ );

    // Set up the Photos Library Client that interacts with the API
    $photosLibraryClient = new PhotosLibraryClient(['credentials' => $authCredentials]);

    // Create a new Album object with at title
    $newAlbum = PhotosLibraryResourceFactory::album("My Album");

    // Make the call to the Library API to create the new album
    $createdAlbum = $photosLibraryClient->createAlbum($newAlbum);

    // The creation call returns the ID of the new album
    $albumId = $createdAlbum->getId();
} catch (\Google\ApiCore\ApiException $exception) {
    // Error during album creation
} catch (\Google\ApiCore\ValidationException $e) {
    // Error during client creation
    echo $exception;
}
// [END sample_usage]

$uploadRetrySettings = [
    'initialRetryDelayMillis' => 1000, // 1 second
    'retryDelayMultiplier' => 1.3,
    'maxRetryDelayMillis' => 10000, // 10 seconds
    'singleTimeoutMillis' => 900000, // 15 minutes
    'maxNumRetries' => 5,
    'retryableCodes' => [ApiStatus::DEADLINE_EXCEEDED, ApiStatus::UNAVAILABLE],
    'retryableExceptions' => []
];

$photosLibraryClient = new PhotosLibraryClient([
    'credentials' => $myCredentials,
    'uploadRetrySettings' => $uploadRetrySettings
]);