phpgoogle-photosgoogle-photos-api

Google Photos API add to album


I am getting a error I cannot work out the reason for in

   public function album_addIds($itemIds, $albumId) {
        if (!is_array($itemIds)) {
          $itemIds = [$itemIds];
        }
        try {
          $response = $this->service->batchAddMediaItemsToAlbum($albumId, $itemIds);
        } catch (\Exception $ex) {
          $noop = 1;
        }
      }

Which give the highly helpful error message:

" Expect array. "

when the Exception occurs. $albumId is a string and as per code (and checking at breakpoint) $itemIds is an array.

enter image description here


Solution

  • Are you using the PHP sample code? The arguments in the sample code are the wrong way round

    Google wrote:

    $response = $photosLibraryClient->batchAddMediaItemsToAlbum($albumId, $mediaItemIds);
    

    whereas the correct code is

        $response = $photosLibraryClient->batchAddMediaItemsToAlbum($mediaItemIds, $albumId);
    

    The OAuth sample code is also wrong, infuriatingly. They assign the access_token to the creds session variable, where they mean refresh_token