Search code examples
google-apipicasagoogle-pickergoogle-photos

How to download the original image from Google Photo with an `id` from Google Picker v3


I am trying to download the full image from my personal Google Photo account.

The image itself was shot with iPhone 6+ at a resolution of 2448×3264 but the biggest size I can get so far is a thumbnail size at 384x512.

Here is the data returned from the Google Picker API v3:

> data.docs[0]
{ 
   id:"6249684261772136370", 
   mediaKey:"AF1QipPWLtKuyF09rcIQd4UT2tjb1YxkWSypm6PHXfeX",
   mimeType:"application/vnd.google-apps.photo",
   name:"IMG_5853.JPG",
   parentId:"6249684260517294833",
   serviceId: "picasa",
   thumbnails: (5) [{…}, {…}, {…}, {…}, {…}],
   type:"photo",
   url:"https://picasaweb.google.com/105232457300095210093/ALBUM_NAME#HASH"
}

Here are the scopes I declared when requesting the access_token using OAuth2

"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/userinfo.profile",
"https://www.googleapis.com/auth/photos",
"https://www.googleapis.com/auth/drive",
"https://picasaweb.google.com/data/"

Here is the request I sent to the "image metadata" endpoint with gdata version set to 3: https://picasaweb.google.com/data/entry/api/user/default/albumid/6249684260517294833/photoid/6249684261772136370

And get the following XML back https://pastebin.com/jgXEqftN but the image under <content type="image/jpeg" src="..." /> is still a thumbnail.

I know there must be a way for this to work since company like filestack can download the full-size image. Any comments/suggestions?


Please note that I am aware that Google photo and Google drive are two different products. But since you can access the images from Google photo through Google drive, and also in the Picker's documentation, it explicitly gives an example of using Google Drive v3 API, I thought I'll give the example a try:

curl --header "Authorization: Bearer ya29.GlsABSW1XLQRocTsxsFlGKmVnx3iCwjAxQCFWG-3YH9nM6IYdLyp8x9v4XLglUEMK1XKsgf8SjYzRpbHJa5xDat5M7PcOfJhViOZAa-S6aAGuWKPe98AJ_y2QtH7" https://www.googleapis.com/drive/v3/files/6244822006604119090\?alt\=media
{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "notFound",
    "message": "File not found: 6244822006604119090.",
    "locationType": "parameter",
    "location": "fileId"
   }
  ],
  "code": 404,
  "message": "File not found: 6244822006604119090."
 }
}

Solution

  • The problem is solved, but not without a sense of frustration and a tingling feeling of why this is not documented anywhere.

    To get the original image, I need to url hack any of the returned thumbnail urls. For example, given the following

    Notice the /s72 in the url. By replacing it with /s0, we'll get the uncropped image. Want the image to be 1024px wide? Pass in /s1024. Here is the javascript code for doing so

    thumbnail_url.replace(/\/s\S+?\//g, "/s0/")