f2calv / CasCap.Apis.GooglePhotos

*unofficial* Google Photos REST API library for .NET projects.
MIT License
60 stars 11 forks source link

Getting "Request contains an invalid media item id" error when adding photo to an album. #118

Closed rgelb closed 1 year ago

rgelb commented 1 year ago

I am trying to do the following:

  1. Create an album.
  2. Add existing photos to that album.

So I do the following:

// boilerplate to connect to google api

List<MediaItem> mediaItems = await googlePhotosSvc.GetMediaItemsAsync();
Album album= await googlePhotosSvc.CreateAlbumAsync(albumName);

foreach (var item in mediaItems) {
    bool success = await googlePhotosSvc.AddMediaItemsToAlbumAsync(album.id, new string[] { item.id });
}

It blows up on googlePhotosSvc.AddMediaItemsToAlbumAsync with Request contains an invalid media item id.

I've played around with adding scopes and at this point I have GooglePhotosScope.AppendOnly, GooglePhotosScope.ReadOnly, GooglePhotosScope.AppCreatedData, GooglePhotosScope.Sharing. But I am not sure what exactly is the problem. I've also tried adding photos in batches, but I get the same error.

The API call looks like this in Fiddler:

POST /v1/albums/ALvc__nJoKD2Rfh9rav5sQ7U9lm5ClQ3F_tVQ-mBANpi0pjGMfs5wn8eJ1gD2ibjQNbLsD3SHeI3:batchAddMediaItems HTTP/1.1

with the body of:

{"mediaItemIds":["ALvc__kuVUBPmBfk8AkGiXLrvxLj1tOdkGaoMtp0AmPqEbcP-hI13wILoiFpCzUXc9xe6zk2eMnsTGry-3SaS4znQZa_qFQwxQ"]}

And it returns

{
  "error": {
    "code": 400,
    "message": "Request contains an invalid media item id.",
    "status": "INVALID_ARGUMENT"
  }
}

What am I missing?

rgelb commented 1 year ago

@f2calv I am closing the ticket because there is nothing the library can do about it. After doing a bit of research, turns out that you can only perform this operation with photos that your app added to an album that your app added.

I was trying to add a photo that I added via the browser to an album that was created via the API.

Google Photos API documentation should state this upfront in capital letters.

f2calv commented 1 year ago

Ok yes that's right, you can only add photos to an album which you have uploaded via the API... which is a shame.

Thanks for the update :)