0

I am reading the Google Photos API documentation. I can't find out what mediaItemId is, see for example here:

https://developers.google.com/photos/library/guides/access-media-items#get-media-item

There are some other questions that might be related, but they have no answers:

How to get mediaItemId of a Google photo using its shared URL?

Leo
  • 4,136
  • 6
  • 48
  • 72

1 Answers1

1

I've not used the API but I'm familiar with other Google services and am a Photos user.

If you consider you're experience with photos.google.com, you browse a somewhat unstructured list of all your photos. The Photos (phone|browser) apps do categorize photos by date but you have to search to filter by other metadata to find the specific photo(s) that you're seeking. Or you happy-scroll through years of photos of your cat.

This contrasts with another common metaphor for arranging files in which a hierarchy of folders is used to categorize the content e.g. /photos/cats/2022 but this mechanism is limited because you can only really navigate through one dimension (the folders).

Considerable metadata (type, width|height, creation date etc.) is associated with each photo and it is customary in schemas like this to construct a unique ID for each object. The unique ID is sometimes exposed to the end-user but not necessarily. Identifiers are generally for the system's own purposes.

With Photos, there are public, unique identifiers in the form of URLs for each photos but evidently the id and the URL although probably related (perhaps via a hash) aren't obviously related.

So, since it's not always possible to specific a photo uniquely by e.g. "The one of my dog where he's wearing sunglasses because of the eclipse" and the absence of folders, a really powerful alternative (which you'll need to employ) is to search for some subset of the photos and then iterate over the results.

It appears that the Photos service has such a search to which you provide Filters and each of the items in the results will be a MediaItem (uniquely identified by id).

Unlike the file system example above, because Photos does not use a fixed hierarchy, we can view our Photos by filtering them using an extensive set of metadata: photos of cats, taken in 2022, using my phone.

DazWilkin
  • 32,823
  • 5
  • 47
  • 88
  • Thanks, yes that part sounds ok. But all I have is an URL in the form https://photos.google.com/share/[LONG-STRING]. mediaItemId is related to that URL in some way, but how? – Leo Jan 07 '22 at 04:04
  • 1
    I suspect (!) you cannot. There's no obvious [Filters](https://developers.google.com/photos/library/reference/rest/v1/mediaItems/search#Filters) that allows you to use the URL to identify a specific image using the API – DazWilkin Jan 07 '22 at 04:07
  • But it seems like it can be done. The site https://publicalbum.org/ does a conversion from an URL of the form above to https://lh3.googleusercontent.com/[ANOTHER-LONG-STRING]. Either that site uses some magic or Google Photos API. – Leo Jan 07 '22 at 04:12
  • 1
    I didn't say it cannot be done. I said it doesn't appear that you can go from a URL to a MediaItem ID using Google's API. I also said I'm unfamiliar with the API ;-) I'm also unfamiliar with publicalbum.org. If you (OAuth2) authenticate to publicalbum.org then it could GET the Photos URL and upload it to its own repo **without** using the Photos API. – DazWilkin Jan 07 '22 at 04:22
  • Thanks for your comments. I think you are right, but it makes me a bit disappointed. Looks like the only way still is Puppeteer. – Leo Jan 07 '22 at 15:06
  • 1
    What is your goal? – DazWilkin Jan 07 '22 at 16:47
  • Good question. I want to get a link to the image I can use on a web page. (A googleusercontent.com link.) – Leo Jan 07 '22 at 18:25
  • 1
    If you share a photo in Photos, grab the link and open it, the image link in the result is a `googleusercontent.com` URL. I don't know for how long that link will remain valid. Using Photos in Google's API Explorer, the aforementioned [`search`](https://developers.google.com/photos/library/reference/rest/v1/mediaItems/search) method, I was able to find the same photo (that I'd shared) by filtering by date. The results included 2 `mediaItems` (I have 2 photos from that day). The `baseUrl` in the results is also a `googleusercontent.com` URL and I was able to browse that. – DazWilkin Jan 07 '22 at 18:50
  • Yes, it is not an official way to do it, but it is the only way I have been able to find. (In my case I can simply check if the `googleusercontent.com` URL is still alive. And refresh it if needed.) – Leo Jan 07 '22 at 21:11