I would like to have all shared albums of a certain google account automatically into a Drupal website.
I was able to establish a connection with 'Google_photos_api' and show all shared albums on site with code below.
<?php
$GooglePhotosService = \Drupal::service('google_photos_api.client');
try {
$optParams=array("pageSize" => 50);
$SharedAlbumlijst = $GooglePhotosService->googleServicePhotosLibrary->sharedAlbums->listSharedAlbums($optParams);
ksm($SharedAlbumlijst);
echo '<div id="GooglePhotos" class="grid views-view-grid">';
echo '<div class="row">';
foreach ($SharedAlbumlijst as $album) {
echo '<div class="col-6 col-sm-6 col-md-4 col-lg-4 col-xl-3" style="margin-bottom: 10px;">';
// Get some properties of an album
$albumId = $album->getId();
$title = $album->getTitle();
$productUrl = $album->getProductUrl();
$coverPhotoBaseUrl = $album->getCoverPhotoBaseUrl() . '=w200-h200-c';
echo '<h5>' . $title . '</h5>';
echo '<a href="' . $coverPhotoBaseUrl . '" id="' . $albumId . '">';
echo '<img src="' . $coverPhotoBaseUrl . '" alt="' . $title . '">';
echo '</a>';
echo '</div>';
}
echo '</div>';
}
catch (Exception $e) {
ksm($e);
}
The problem I cannot figure out is to list all media-items of a given album. Code below is not functioning. I don't know how to pass the albumID into this??
<?php
$GooglePhotosService = \Drupal::service('google_photos_api.client');
try {
$albumId = 'ANfpKL0unQw8nWACRpVCPj0JxmZ5JHkX_xCecI-VPFxKrFScPPfpE8HakFWvKG3KFVXNnNyigXB0';
$optParams = ['albumId' => $albumId];
$mediaItems = $GooglePhotosService->googleServicePhotosLibrary->mediaItems->search($optParams);
ksm($MediaItems);
}
catch (Exception $e) {
ksm($e);
}
Any help would be great!!
Thanks in advance!!
Error code:
The website encountered an unexpected error. Please try again later.
TypeError: Argument 1 passed to Google_Service_PhotosLibrary_Resource_MediaItems::search() must be an instance of Google_Service_PhotosLibrary_SearchMediaItemsRequest, array given, called in C:\Xampp2\htdocs\Demertr\modules\contrib\php\php.module(81) : eval()'d code on line 7 in Google_Service_PhotosLibrary_Resource_MediaItems->search() (line 79 of vendor\google\apiclient-services\src\Google\Service\PhotosLibrary\Resource\MediaItems.php).
MediaItems.php
class Google_Service_PhotosLibrary_Resource_MediaItems extends Google_Service_Resource {
public function search(Google_Service_PhotosLibrary_SearchMediaItemsRequest $postBody, $optParams = []) {
$params = ['postBody' => $postBody];
$params = array_merge($params, $optParams);
return $this->call('search', [$params], 'Google_Service_PhotosLibrary_SearchMediaItemsResponse');
}
}
SearchMediaItemsRequest.php
class Google_Service_PhotosLibrary_SearchMediaItemsRequest extends Google_Model {
public $albumId;
protected $filtersType = 'Google_Service_PhotosLibrary_Filters';
protected $filtersDataType = '';
public $pageSize;
public $pageToken;
...