teaching machines

CS 491 Lecture 22 – Working with Picasa Web

November 19, 2013 by . Filed under cs491 mobile, fall 2013, lectures.

Agenda

Exercise

Today let’s make a browser for Picasa Web. The overarching design is this:

The ideas here are simple, but the complicating part is that our images are stored using a third-party web service. We will be stepping into some else’s system. Often you can find language-specific SDKs for working with web services, but these are rarely perfect and hide away the magic inner workings that I find essential to know if I’m going to build on top of them. So, instead of using an SDK, we will be issuing HTTP requests with the native platform’s API. JSON will be flying around left and right.

I tried hard to find good SDKs. Ultimately, I found the most success by just reading the HTTP API documentation at https://developers.google.com/picasa-web/docs/2.0/developers_guide_protocol.

Note that I don’t really address asynchronous operations in the code below. Anything that goes out to the Internet should ultimately be done on a separate thread. In my own implementation, I temporarily ignored this fact on iOS and used AsyncTask in Android.

Authentication

First, we need to get authentication to work with a Picasa Web account. You’ll need a Google account, and I recommend it be one that you share with your group—not your personal one.

Eventually, authentication will be done directly in your app. This is non-trivial to do, so we will defer this problem at the moment. Instead, we’ll authenticate via the browser and borrow the access token that we’ll need to be attached to all of our HTTP requests.

Visit https://developers.google.com/oauthplayground, authorize Picasa Web, exchange tokens, and yank the access token for use in your app.

Fetching a list of albums

To get a list of the albums belonging to the user who owns the access token, we need to issue an HTTP GET request to the following URL:

https://picasaweb.google.com/data/feed/api/user/default?alt=json&prettyprint=true

The GET parameters are there to force a JSON result (instead of the default XML) and format it so that if we log the JSON, we’ll actually be able to read it.

Ultimately the request sent down the wire has this form:

GET /data/feed/api/user/default?alt=json&prettyprint=true HTTP/1.1
Host: picasaweb.google.com
Content-length: 0
Authorization: Bearer YOURACCESSTOKEN

You’ll need to add the Authorization header yourself. The others will be automatically set by the HTTP request library. See the bottom sections for details on how to construct and send requests.

The resulting JSON has this form:

{
 "version": "1.0",
 "encoding": "UTF-8",
 "feed": {
  "xmlns": "http://www.w3.org/2005/Atom",
  "xmlns$gphoto": "http://schemas.google.com/photos/2007",
  "xmlns$media": "http://search.yahoo.com/mrss/",
  "xmlns$openSearch": "http://a9.com/-/spec/opensearchrss/1.0/",
  "id": {
   "$t": "https://picasaweb.google.com/data/feed/api/user/default"
  },
  "updated": {
   "$t": "2013-11-19T13:49:24.705Z"
  },
  "category": [
   {
    "scheme": "http://schemas.google.com/g/2005#kind",
    "term": "http://schemas.google.com/photos/2007#user"
   }
  ],
  "title": {
   "$t": "110180137313777559136",
   "type": "text"
  },
  "subtitle": {
   "$t": "",
   "type": "text"
  },
  "icon": {
   "$t": "https://lh5.googleusercontent.com/-uyWpVX-ghp4/AAAAAAAAAAI/AAAAAAAAAKY/5b3aIvNz9V4/s64-c/110180137313777559136.jpg"
  },
  "link": [
   {
    "rel": "http://schemas.google.com/g/2005#feed",
    "type": "application/atom+xml",
    "href": "https://picasaweb.google.com/data/feed/api/user/110180137313777559136?alt=json"
   },
   {
    "rel": "http://schemas.google.com/g/2005#post",
    "type": "application/atom+xml",
    "href": "https://picasaweb.google.com/data/feed/api/user/110180137313777559136?alt=json"
   },
   {
    "rel": "alternate",
    "type": "text/html",
    "href": "https://picasaweb.google.com/110180137313777559136"
   },
   {
    "rel": "http://schemas.google.com/photos/2007#slideshow",
    "type": "application/x-shockwave-flash",
    "href": "https://static.googleusercontent.com/external_content/picasaweb.googleusercontent.com/slideshow.swf?host=picasaweb.google.com&RGB=0x000000&feed=https://picasaweb.google.com/data/feed/api/user/110180137313777559136?alt%3Drss"
   },
   {
    "rel": "self",
    "type": "application/atom+xml",
    "href": "https://picasaweb.google.com/data/feed/api/user/110180137313777559136?alt=json&start-index=1&max-results=1000"
   }
  ],
  "author": [
   {
    "name": {
     "$t": "Chris Johnson"
    },
    "uri": {
     "$t": "https://picasaweb.google.com/110180137313777559136"
    }
   }
  ],
  "generator": {
   "$t": "Picasaweb",
   "version": "1.00",
   "uri": "http://picasaweb.google.com/"
  },
  "openSearch$totalResults": {
   "$t": 8
  },
  "openSearch$startIndex": {
   "$t": 1
  },
  "openSearch$itemsPerPage": {
   "$t": 1000
  },
  "gphoto$user": {
   "$t": "110180137313777559136"
  },
  "gphoto$nickname": {
   "$t": "Chris Johnson"
  },
  "gphoto$thumbnail": {
   "$t": "https://lh5.googleusercontent.com/-uyWpVX-ghp4/AAAAAAAAAAI/AAAAAAAAAKY/5b3aIvNz9V4/s64-c/110180137313777559136.jpg"
  },
  "gphoto$quotalimit": {
   "$t": "16106127360"
  },
  "gphoto$quotacurrent": {
   "$t": "495865723"
  },
  "gphoto$maxPhotosPerAlbum": {
   "$t": 1100
  },
  "entry": [
   {
    "id": {
     "$t": "https://picasaweb.google.com/data/entry/api/user/110180137313777559136/albumid/1000000477559136?alt=json"
    },
    "published": {
     "$t": "2013-07-23T02:57:58.000Z"
    },
    "updated": {
     "$t": "2013-07-23T02:57:58.918Z"
    },
    "category": [
     {
      "scheme": "http://schemas.google.com/g/2005#kind",
      "term": "http://schemas.google.com/photos/2007#album"
     }
    ],
    "title": {
     "$t": "Auto Backup",
     "type": "text"
    },
    "summary": {
     "$t": "",
     "type": "text"
    },
    "rights": {
     "$t": "protected",
     "type": "text"
    },
    "link": [
     {
      "rel": "http://schemas.google.com/g/2005#feed",
      "type": "application/atom+xml",
      "href": "https://picasaweb.google.com/data/feed/api/user/110180137313777559136/albumid/1000000477559136?alt=json"
     },
     {
      "rel": "alternate",
      "type": "text/html",
      "href": "https://picasaweb.google.com/110180137313777559136?alabel=small_instant_upload"
     },
     {
      "rel": "self",
      "type": "application/atom+xml",
      "href": "https://picasaweb.google.com/data/entry/api/user/110180137313777559136/albumid/1000000477559136?alt=json"
     }
    ],
    "author": [
     {
      "name": {
       "$t": "Chris Johnson"
      },
      "uri": {
       "$t": "https://picasaweb.google.com/110180137313777559136"
      }
     }
    ],
    "gphoto$id": {
     "$t": "1000000477559136"
    },
    "gphoto$name": {
     "$t": "InstantUpload"
    },
    "gphoto$access": {
     "$t": "private"
    },
    "gphoto$timestamp": {
     "$t": "1374548278000"
    },
    "gphoto$numphotos": {
     "$t": 0
    },
    "gphoto$user": {
     "$t": "110180137313777559136"
    },
    "gphoto$nickname": {
     "$t": "Chris Johnson"
    },
    "gphoto$albumType": {
     "$t": "InstantUpload"
    },
    "media$group": {
     "media$content": [
      {
       "url": "https://lh6.googleusercontent.com/-2BYFjmoT2zU/Ue3xN3YST_E/AAAAAAAAAKw/pHWbLquGK_I/InstantUpload.jpg",
       "type": "image/jpeg",
       "medium": "image"
      }
     ],
     "media$credit": [
      {
       "$t": "Chris Johnson"
      }
     ],
     "media$description": {
      "$t": "Auto Backup",
      "type": "plain"
     },
     "media$keywords": {},
     "media$thumbnail": [
      {
       "url": "https://lh6.googleusercontent.com/-2BYFjmoT2zU/Ue3xN3YST_E/AAAAAAAAAKw/pHWbLquGK_I/s160-c/InstantUpload.jpg",
       "height": 160,
       "width": 160
      }
     ],
     "media$title": {
      "$t": "Auto Backup",
      "type": "plain"
     }
    }
   },
   {
    "id": {
     "$t": "https://picasaweb.google.com/data/entry/api/user/110180137313777559136/albumid/5945163810807292785?alt=json"
    },
    "published": {
     "$t": "2013-11-12T00:31:56.000Z"
    },
    "updated": {
     "$t": "2013-11-19T13:49:24.705Z"
    },
    "category": [
     {
      "scheme": "http://schemas.google.com/g/2005#kind",
      "term": "http://schemas.google.com/photos/2007#album"
     }
    ],
    "title": {
     "$t": "foo",
     "type": "text"
    },
    "summary": {
     "$t": "",
     "type": "text"
    },
    "rights": {
     "$t": "protected",
     "type": "text"
    },
    "link": [
     {
      "rel": "http://schemas.google.com/g/2005#feed",
      "type": "application/atom+xml",
      "href": "https://picasaweb.google.com/data/feed/api/user/110180137313777559136/albumid/5945163810807292785?alt=json"
     },
     {
      "rel": "alternate",
      "type": "text/html",
      "href": "https://picasaweb.google.com/110180137313777559136/Foo"
     },
     {
      "rel": "self",
      "type": "application/atom+xml",
      "href": "https://picasaweb.google.com/data/entry/api/user/110180137313777559136/albumid/5945163810807292785?alt=json"
     },
     {
      "rel": "edit",
      "type": "application/atom+xml",
      "href": "https://picasaweb.google.com/data/entry/api/user/110180137313777559136/albumid/5945163810807292785/17?alt=json"
     },
     {
      "rel": "http://schemas.google.com/acl/2007#accessControlList",
      "type": "application/atom+xml",
      "href": "https://picasaweb.google.com/data/entry/api/user/110180137313777559136/albumid/5945163810807292785/acl?alt=json"
     }
    ],
    "author": [
     {
      "name": {
       "$t": "Chris Johnson"
      },
      "uri": {
       "$t": "https://picasaweb.google.com/110180137313777559136"
      }
     }
    ],
    "gphoto$id": {
     "$t": "5945163810807292785"
    },
    "gphoto$name": {
     "$t": "Foo"
    },
    "gphoto$location": {
     "$t": ""
    },
    "gphoto$access": {
     "$t": "protected"
    },
    "gphoto$timestamp": {
     "$t": "1384216316000"
    },
    "gphoto$numphotos": {
     "$t": 5
    },
    "gphoto$numphotosremaining": {
     "$t": 1095
    },
    "gphoto$bytesUsed": {
     "$t": "1985644"
    },
    "gphoto$user": {
     "$t": "110180137313777559136"
    },
    "gphoto$nickname": {
     "$t": "Chris Johnson"
    },
    "gphoto$commentingEnabled": {
     "$t": "true"
    },
    "gphoto$commentCount": {
     "$t": 0
    },
    "media$group": {
     "media$content": [
      {
       "url": "https://lh6.googleusercontent.com/-dwZvxYxc9LA/UoF2_LKtI3E/AAAAAAAAAQg/lng1Ky4OXU4/Foo.jpg",
       "type": "image/jpeg",
       "medium": "image"
      }
     ],
     "media$credit": [
      {
       "$t": "Chris Johnson"
      }
     ],
     "media$description": {
      "$t": "",
      "type": "plain"
     },
     "media$keywords": {},
     "media$thumbnail": [
      {
       "url": "https://lh6.googleusercontent.com/-dwZvxYxc9LA/UoF2_LKtI3E/AAAAAAAAAQg/lng1Ky4OXU4/s160-c/Foo.jpg",
       "height": 160,
       "width": 160
      }
     ],
     "media$title": {
      "$t": "foo",
      "type": "plain"
     }
    }
   },
   {
    "id": {
     "$t": "https://picasaweb.google.com/data/entry/api/user/110180137313777559136/albumid/5945427314441898705?alt=json"
    },
    "published": {
     "$t": "2013-11-12T17:34:28.000Z"
    },
    "updated": {
     "$t": "2013-11-13T18:09:33.522Z"
    },
    "category": [
     {
      "scheme": "http://schemas.google.com/g/2005#kind",
      "term": "http://schemas.google.com/photos/2007#album"
     }
    ],
    "title": {
     "$t": "Drop Box",
     "type": "text"
    },
    "summary": {
     "$t": "Default album for newly uploaded photos.",
     "type": "text"
    },
    "rights": {
     "$t": "private",
     "type": "text"
    },
    "link": [
     {
      "rel": "http://schemas.google.com/g/2005#feed",
      "type": "application/atom+xml",
      "href": "https://picasaweb.google.com/data/feed/api/user/110180137313777559136/albumid/5945427314441898705?alt=json&authkey=Gv1sRgCNrlx7renMzGrwE"
     },
     {
      "rel": "alternate",
      "type": "text/html",
      "href": "https://picasaweb.google.com/110180137313777559136/DropBox?authkey=Gv1sRgCNrlx7renMzGrwE"
     },
     {
      "rel": "self",
      "type": "application/atom+xml",
      "href": "https://picasaweb.google.com/data/entry/api/user/110180137313777559136/albumid/5945427314441898705?alt=json&authkey=Gv1sRgCNrlx7renMzGrwE"
     },
     {
      "rel": "edit",
      "type": "application/atom+xml",
      "href": "https://picasaweb.google.com/data/entry/api/user/110180137313777559136/albumid/5945427314441898705/31?alt=json&authkey=Gv1sRgCNrlx7renMzGrwE"
     },
     {
      "rel": "http://schemas.google.com/acl/2007#accessControlList",
      "type": "application/atom+xml",
      "href": "https://picasaweb.google.com/data/entry/api/user/110180137313777559136/albumid/5945427314441898705/acl?alt=json&authkey=Gv1sRgCNrlx7renMzGrwE"
     }
    ],
    "author": [
     {
      "name": {
       "$t": "Chris Johnson"
      },
      "uri": {
       "$t": "https://picasaweb.google.com/110180137313777559136"
      }
     }
    ],
    "gphoto$id": {
     "$t": "5945427314441898705"
    },
    "gphoto$name": {
     "$t": "DropBox"
    },
    "gphoto$location": {
     "$t": ""
    },
    "gphoto$access": {
     "$t": "private"
    },
    "gphoto$timestamp": {
     "$t": "1384277668000"
    },
    "gphoto$numphotos": {
     "$t": 27
    },
    "gphoto$numphotosremaining": {
     "$t": 1073
    },
    "gphoto$bytesUsed": {
     "$t": "9666"
    },
    "gphoto$user": {
     "$t": "110180137313777559136"
    },
    "gphoto$nickname": {
     "$t": "Chris Johnson"
    },
    "gphoto$commentingEnabled": {
     "$t": "true"
    },
    "gphoto$commentCount": {
     "$t": 0
    },
    "gphoto$albumType": {
     "$t": "Default"
    },
    "media$group": {
     "media$content": [
      {
       "url": "https://lh4.googleusercontent.com/-UoWGJDWs7TQ/UoJmpGs2ytE/AAAAAAAAAP8/jLuCAwEu5Ro/DropBox.jpg",
       "type": "image/jpeg",
       "medium": "image"
      }
     ],
     "media$credit": [
      {
       "$t": "Chris Johnson"
      }
     ],
     "media$description": {
      "$t": "Default album for newly uploaded photos.",
      "type": "plain"
     },
     "media$keywords": {},
     "media$thumbnail": [
      {
       "url": "https://lh4.googleusercontent.com/-UoWGJDWs7TQ/UoJmpGs2ytE/AAAAAAAAAP8/jLuCAwEu5Ro/s160-c/DropBox.jpg",
       "height": 160,
       "width": 160
      }
     ],
     "media$title": {
      "$t": "Drop Box",
      "type": "plain"
     }
    }
   },
   {
    "id": {
     "$t": "https://picasaweb.google.com/data/entry/api/user/110180137313777559136/albumid/5878619262205595681?alt=json"
    },
    "published": {
     "$t": "2013-05-16T16:45:33.000Z"
    },
    "updated": {
     "$t": "2013-05-16T16:51:17.700Z"
    },
    "category": [
     {
      "scheme": "http://schemas.google.com/g/2005#kind",
      "term": "http://schemas.google.com/photos/2007#album"
     }
    ],
    "title": {
     "$t": "Profile Photos",
     "type": "text"
    },
    "summary": {
     "$t": "Album for profile photos",
     "type": "text"
    },
    "rights": {
     "$t": "public",
     "type": "text"
    },
    "link": [
     {
      "rel": "http://schemas.google.com/g/2005#feed",
      "type": "application/atom+xml",
      "href": "https://picasaweb.google.com/data/feed/api/user/110180137313777559136/albumid/5878619262205595681?alt=json"
     },
     {
      "rel": "alternate",
      "type": "text/html",
      "href": "https://picasaweb.google.com/110180137313777559136/ProfilePhotos02"
     },
     {
      "rel": "self",
      "type": "application/atom+xml",
      "href": "https://picasaweb.google.com/data/entry/api/user/110180137313777559136/albumid/5878619262205595681?alt=json"
     },
     {
      "rel": "edit",
      "type": "application/atom+xml",
      "href": "https://picasaweb.google.com/data/entry/api/user/110180137313777559136/albumid/5878619262205595681/7?alt=json"
     },
     {
      "rel": "http://schemas.google.com/acl/2007#accessControlList",
      "type": "application/atom+xml",
      "href": "https://picasaweb.google.com/data/entry/api/user/110180137313777559136/albumid/5878619262205595681/acl?alt=json"
     }
    ],
    "author": [
     {
      "name": {
       "$t": "Chris Johnson"
      },
      "uri": {
       "$t": "https://picasaweb.google.com/110180137313777559136"
      }
     }
    ],
    "gphoto$id": {
     "$t": "5878619262205595681"
    },
    "gphoto$name": {
     "$t": "ProfilePhotos02"
    },
    "gphoto$location": {
     "$t": ""
    },
    "gphoto$access": {
     "$t": "public"
    },
    "gphoto$timestamp": {
     "$t": "1368722733000"
    },
    "gphoto$numphotos": {
     "$t": 2
    },
    "gphoto$numphotosremaining": {
     "$t": 1098
    },
    "gphoto$bytesUsed": {
     "$t": "287957"
    },
    "gphoto$user": {
     "$t": "110180137313777559136"
    },
    "gphoto$nickname": {
     "$t": "Chris Johnson"
    },
    "gphoto$commentingEnabled": {
     "$t": "true"
    },
    "gphoto$commentCount": {
     "$t": 0
    },
    "gphoto$albumType": {
     "$t": "ProfilePhotos"
    },
    "media$group": {
     "media$content": [
      {
       "url": "https://lh3.googleusercontent.com/-GQEmJ0Fn740/UZUNEp2IkCE/AAAAAAAAAJ4/zzlbQ8Dcgow/ProfilePhotos02.jpg",
       "type": "image/jpeg",
       "medium": "image"
      }
     ],
     "media$credit": [
      {
       "$t": "Chris Johnson"
      }
     ],
     "media$description": {
      "$t": "",
      "type": "plain"
     },
     "media$keywords": {},
     "media$thumbnail": [
      {
       "url": "https://lh3.googleusercontent.com/-GQEmJ0Fn740/UZUNEp2IkCE/AAAAAAAAAJ4/zzlbQ8Dcgow/s160-c/ProfilePhotos02.jpg",
       "height": 160,
       "width": 160
      }
     ],
     "media$title": {
      "$t": "Profile Photos",
      "type": "plain"
     }
    }
   },
   {
    "id": {
     "$t": "https://picasaweb.google.com/data/entry/api/user/110180137313777559136/albumid/5878619038264180705?alt=json"
    },
    "published": {
     "$t": "2013-05-16T16:44:14.000Z"
    },
    "updated": {
     "$t": "2013-05-16T16:49:24.162Z"
    },
    "category": [
     {
      "scheme": "http://schemas.google.com/g/2005#kind",
      "term": "http://schemas.google.com/photos/2007#album"
     }
    ],
    "title": {
     "$t": "Profile Photos (draft)",
     "type": "text"
    },
    "summary": {
     "$t": "Album for profile photos that are uploaded but not yet displayed publicly",
     "type": "text"
    },
    "rights": {
     "$t": "protected",
     "type": "text"
    },
    "link": [
     {
      "rel": "http://schemas.google.com/g/2005#feed",
      "type": "application/atom+xml",
      "href": "https://picasaweb.google.com/data/feed/api/user/110180137313777559136/albumid/5878619038264180705?alt=json"
     },
     {
      "rel": "alternate",
      "type": "text/html",
      "href": "https://picasaweb.google.com/110180137313777559136/ProfilePhotos"
     },
     {
      "rel": "self",
      "type": "application/atom+xml",
      "href": "https://picasaweb.google.com/data/entry/api/user/110180137313777559136/albumid/5878619038264180705?alt=json"
     },
     {
      "rel": "edit",
      "type": "application/atom+xml",
      "href": "https://picasaweb.google.com/data/entry/api/user/110180137313777559136/albumid/5878619038264180705/10?alt=json"
     },
     {
      "rel": "http://schemas.google.com/acl/2007#accessControlList",
      "type": "application/atom+xml",
      "href": "https://picasaweb.google.com/data/entry/api/user/110180137313777559136/albumid/5878619038264180705/acl?alt=json"
     }
    ],
    "author": [
     {
      "name": {
       "$t": "Chris Johnson"
      },
      "uri": {
       "$t": "https://picasaweb.google.com/110180137313777559136"
      }
     }
    ],
    "gphoto$id": {
     "$t": "5878619038264180705"
    },
    "gphoto$name": {
     "$t": "ProfilePhotos"
    },
    "gphoto$location": {
     "$t": ""
    },
    "gphoto$access": {
     "$t": "protected"
    },
    "gphoto$timestamp": {
     "$t": "1368722654000"
    },
    "gphoto$numphotos": {
     "$t": 1
    },
    "gphoto$numphotosremaining": {
     "$t": 1099
    },
    "gphoto$bytesUsed": {
     "$t": "201190"
    },
    "gphoto$user": {
     "$t": "110180137313777559136"
    },
    "gphoto$nickname": {
     "$t": "Chris Johnson"
    },
    "gphoto$commentingEnabled": {
     "$t": "true"
    },
    "gphoto$commentCount": {
     "$t": 0
    },
    "media$group": {
     "media$content": [
      {
       "url": "https://lh4.googleusercontent.com/-uJ84XfpQ1CA/UZUM3nmVv-E/AAAAAAAAAJs/nNSZqiVZNd4/ProfilePhotos.jpg",
       "type": "image/jpeg",
       "medium": "image"
      }
     ],
     "media$credit": [
      {
       "$t": "Chris Johnson"
      }
     ],
     "media$description": {
      "$t": "",
      "type": "plain"
     },
     "media$keywords": {},
     "media$thumbnail": [
      {
       "url": "https://lh4.googleusercontent.com/-uJ84XfpQ1CA/UZUM3nmVv-E/AAAAAAAAAJs/nNSZqiVZNd4/s160-c/ProfilePhotos.jpg",
       "height": 160,
       "width": 160
      }
     ],
     "media$title": {
      "$t": "Profile Photos (draft)",
      "type": "plain"
     }
    }
   },
   {
    "id": {
     "$t": "https://picasaweb.google.com/data/entry/api/user/110180137313777559136/albumid/5733890405984596385?alt=json"
    },
    "published": {
     "$t": "2012-04-21T07:00:00.000Z"
    },
    "updated": {
     "$t": "2013-05-09T21:14:09.373Z"
    },
    "category": [
     {
      "scheme": "http://schemas.google.com/g/2005#kind",
      "term": "http://schemas.google.com/photos/2007#album"
     }
    ],
    "title": {
     "$t": "April 21, 2012",
     "type": "text"
    },
    "summary": {
     "$t": "",
     "type": "text"
    },
    "rights": {
     "$t": "private",
     "type": "text"
    },
    "link": [
     {
      "rel": "http://schemas.google.com/g/2005#feed",
      "type": "application/atom+xml",
      "href": "https://picasaweb.google.com/data/feed/api/user/110180137313777559136/albumid/5733890405984596385?alt=json&authkey=Gv1sRgCOCyr-rFq8eTXg"
     },
     {
      "rel": "alternate",
      "type": "text/html",
      "href": "https://picasaweb.google.com/110180137313777559136/April212012?authkey=Gv1sRgCOCyr-rFq8eTXg"
     },
     {
      "rel": "self",
      "type": "application/atom+xml",
      "href": "https://picasaweb.google.com/data/entry/api/user/110180137313777559136/albumid/5733890405984596385?alt=json&authkey=Gv1sRgCOCyr-rFq8eTXg"
     },
     {
      "rel": "edit",
      "type": "application/atom+xml",
      "href": "https://picasaweb.google.com/data/entry/api/user/110180137313777559136/albumid/5733890405984596385/7?alt=json&authkey=Gv1sRgCOCyr-rFq8eTXg"
     },
     {
      "rel": "http://schemas.google.com/acl/2007#accessControlList",
      "type": "application/atom+xml",
      "href": "https://picasaweb.google.com/data/entry/api/user/110180137313777559136/albumid/5733890405984596385/acl?alt=json&authkey=Gv1sRgCOCyr-rFq8eTXg"
     }
    ],
    "author": [
     {
      "name": {
       "$t": "Chris Johnson"
      },
      "uri": {
       "$t": "https://picasaweb.google.com/110180137313777559136"
      }
     }
    ],
    "gphoto$id": {
     "$t": "5733890405984596385"
    },
    "gphoto$name": {
     "$t": "April212012"
    },
    "gphoto$location": {
     "$t": ""
    },
    "gphoto$access": {
     "$t": "private"
    },
    "gphoto$timestamp": {
     "$t": "1334991600000"
    },
    "gphoto$numphotos": {
     "$t": 4
    },
    "gphoto$numphotosremaining": {
     "$t": 1096
    },
    "gphoto$bytesUsed": {
     "$t": "1387199"
    },
    "gphoto$user": {
     "$t": "110180137313777559136"
    },
    "gphoto$nickname": {
     "$t": "Chris Johnson"
    },
    "gphoto$commentingEnabled": {
     "$t": "true"
    },
    "gphoto$commentCount": {
     "$t": 0
    },
    "media$group": {
     "media$content": [
      {
       "url": "https://lh6.googleusercontent.com/-TPjtGZSlQfs/T5Le8d27caE/AAAAAAAAAIY/RpRFI_FVBLY/April212012.jpg",
       "type": "image/jpeg",
       "medium": "image"
      }
     ],
     "media$credit": [
      {
       "$t": "Chris Johnson"
      }
     ],
     "media$description": {
      "$t": "",
      "type": "plain"
     },
     "media$keywords": {},
     "media$thumbnail": [
      {
       "url": "https://lh6.googleusercontent.com/-TPjtGZSlQfs/T5Le8d27caE/AAAAAAAAAIY/RpRFI_FVBLY/s160-c/April212012.jpg",
       "height": 160,
       "width": 160
      }
     ],
     "media$title": {
      "$t": "April 21, 2012",
      "type": "plain"
     }
    }
   },
   {
    "id": {
     "$t": "https://picasaweb.google.com/data/entry/api/user/110180137313777559136/albumid/5627056203843436305?alt=json"
    },
    "published": {
     "$t": "2011-07-08T18:51:57.000Z"
    },
    "updated": {
     "$t": "2011-07-08T18:51:57.409Z"
    },
    "category": [
     {
      "scheme": "http://schemas.google.com/g/2005#kind",
      "term": "http://schemas.google.com/photos/2007#album"
     }
    ],
    "title": {
     "$t": "Scrapbook Photos",
     "type": "text"
    },
    "summary": {
     "$t": "Album for scrapbook photos",
     "type": "text"
    },
    "rights": {
     "$t": "public",
     "type": "text"
    },
    "link": [
     {
      "rel": "http://schemas.google.com/g/2005#feed",
      "type": "application/atom+xml",
      "href": "https://picasaweb.google.com/data/feed/api/user/110180137313777559136/albumid/5627056203843436305?alt=json"
     },
     {
      "rel": "alternate",
      "type": "text/html",
      "href": "https://picasaweb.google.com/110180137313777559136/ScrapbookPhotos"
     },
     {
      "rel": "self",
      "type": "application/atom+xml",
      "href": "https://picasaweb.google.com/data/entry/api/user/110180137313777559136/albumid/5627056203843436305?alt=json"
     },
     {
      "rel": "edit",
      "type": "application/atom+xml",
      "href": "https://picasaweb.google.com/data/entry/api/user/110180137313777559136/albumid/5627056203843436305/1?alt=json"
     },
     {
      "rel": "http://schemas.google.com/acl/2007#accessControlList",
      "type": "application/atom+xml",
      "href": "https://picasaweb.google.com/data/entry/api/user/110180137313777559136/albumid/5627056203843436305/acl?alt=json"
     }
    ],
    "author": [
     {
      "name": {
       "$t": "Chris Johnson"
      },
      "uri": {
       "$t": "https://picasaweb.google.com/110180137313777559136"
      }
     }
    ],
    "gphoto$id": {
     "$t": "5627056203843436305"
    },
    "gphoto$name": {
     "$t": "ScrapbookPhotos"
    },
    "gphoto$location": {
     "$t": ""
    },
    "gphoto$access": {
     "$t": "public"
    },
    "gphoto$timestamp": {
     "$t": "1310151117000"
    },
    "gphoto$numphotos": {
     "$t": 0
    },
    "gphoto$numphotosremaining": {
     "$t": 1100
    },
    "gphoto$bytesUsed": {
     "$t": "0"
    },
    "gphoto$user": {
     "$t": "110180137313777559136"
    },
    "gphoto$nickname": {
     "$t": "Chris Johnson"
    },
    "gphoto$commentingEnabled": {
     "$t": "true"
    },
    "gphoto$commentCount": {
     "$t": 0
    },
    "gphoto$albumType": {
     "$t": "ScrapBook"
    },
    "media$group": {
     "media$content": [
      {
       "url": "https://lh6.googleusercontent.com/-DLB1vSz7fec/ThdRzdE-_xE/AAAAAAAAAGY/XpGJcXgLDCk/ScrapbookPhotos.jpg",
       "type": "image/jpeg",
       "medium": "image"
      }
     ],
     "media$credit": [
      {
       "$t": "Chris Johnson"
      }
     ],
     "media$description": {
      "$t": "Scrapbook Photos",
      "type": "plain"
     },
     "media$keywords": {},
     "media$thumbnail": [
      {
       "url": "https://lh6.googleusercontent.com/-DLB1vSz7fec/ThdRzdE-_xE/AAAAAAAAAGY/XpGJcXgLDCk/s160-c/ScrapbookPhotos.jpg",
       "height": 160,
       "width": 160
      }
     ],
     "media$title": {
      "$t": "Scrapbook Photos",
      "type": "plain"
     }
    }
   },
   {
    "id": {
     "$t": "https://picasaweb.google.com/data/entry/api/user/110180137313777559136/albumid/5478634089148928529?alt=json"
    },
    "published": {
     "$t": "2010-06-03T07:00:00.000Z"
    },
    "updated": {
     "$t": "2013-05-09T21:14:07.373Z"
    },
    "category": [
     {
      "scheme": "http://schemas.google.com/g/2005#kind",
      "term": "http://schemas.google.com/photos/2007#album"
     }
    ],
    "title": {
     "$t": "Untitled Album",
     "type": "text"
    },
    "summary": {
     "$t": "",
     "type": "text"
    },
    "rights": {
     "$t": "public",
     "type": "text"
    },
    "link": [
     {
      "rel": "http://schemas.google.com/g/2005#feed",
      "type": "application/atom+xml",
      "href": "https://picasaweb.google.com/data/feed/api/user/110180137313777559136/albumid/5478634089148928529?alt=json"
     },
     {
      "rel": "alternate",
      "type": "text/html",
      "href": "https://picasaweb.google.com/110180137313777559136/UntitledAlbum"
     },
     {
      "rel": "self",
      "type": "application/atom+xml",
      "href": "https://picasaweb.google.com/data/entry/api/user/110180137313777559136/albumid/5478634089148928529?alt=json"
     },
     {
      "rel": "edit",
      "type": "application/atom+xml",
      "href": "https://picasaweb.google.com/data/entry/api/user/110180137313777559136/albumid/5478634089148928529/21?alt=json"
     },
     {
      "rel": "http://schemas.google.com/acl/2007#accessControlList",
      "type": "application/atom+xml",
      "href": "https://picasaweb.google.com/data/entry/api/user/110180137313777559136/albumid/5478634089148928529/acl?alt=json"
     }
    ],
    "author": [
     {
      "name": {
       "$t": "Chris Johnson"
      },
      "uri": {
       "$t": "https://picasaweb.google.com/110180137313777559136"
      }
     }
    ],
    "gphoto$id": {
     "$t": "5478634089148928529"
    },
    "gphoto$name": {
     "$t": "UntitledAlbum"
    },
    "gphoto$location": {
     "$t": ""
    },
    "gphoto$access": {
     "$t": "public"
    },
    "gphoto$timestamp": {
     "$t": "1275548400000"
    },
    "gphoto$numphotos": {
     "$t": 12
    },
    "gphoto$numphotosremaining": {
     "$t": 1088
    },
    "gphoto$bytesUsed": {
     "$t": "5902685"
    },
    "gphoto$user": {
     "$t": "110180137313777559136"
    },
    "gphoto$nickname": {
     "$t": "Chris Johnson"
    },
    "gphoto$commentingEnabled": {
     "$t": "true"
    },
    "gphoto$commentCount": {
     "$t": 0
    },
    "media$group": {
     "media$content": [
      {
       "url": "https://lh6.googleusercontent.com/-iqOWmsmuOJc/TAgErVIRUhE/AAAAAAAAAHk/TAxj6BHNvFs/UntitledAlbum.jpg",
       "type": "image/jpeg",
       "medium": "image"
      }
     ],
     "media$credit": [
      {
       "$t": "Chris Johnson"
      }
     ],
     "media$description": {
      "$t": "",
      "type": "plain"
     },
     "media$keywords": {},
     "media$thumbnail": [
      {
       "url": "https://lh6.googleusercontent.com/-iqOWmsmuOJc/TAgErVIRUhE/AAAAAAAAAHk/TAxj6BHNvFs/s160-c/UntitledAlbum.jpg",
       "height": 160,
       "width": 160
      }
     ],
     "media$title": {
      "$t": "Untitled Album",
      "type": "plain"
     }
    }
   }
  ]
 }
}

The useful information is this dictionary is reached via feed/entry, which is an array of album dictionaries. Within each, title/$t and gphoto$id/$t give us the title and unique identifier, which are enough for us today. We can present the titles in the list and use the identifiers to issue requests on a particular album.

Fetching a list of pictures in an album

To get a list of the pictures in an album, we need to issue an HTTP GET request to the following URL:

https://picasaweb.google.com/data/feed/api/user/default/albumid/ALBUMID?alt=json&prettyprint=true

ALBUMID needs to be replaced by the gphoto$id/$t value you got in the previous section.

Ultimately the request sent down the wire has this form:

GET /data/feed/api/user/default/albumid/ALBUMID?alt=json&prettyprint=true HTTP/1.1
Host: picasaweb.google.com
Content-length: 0
Authorization: Bearer YOURACCESSTOKEN

You’ll need to add the Authorization header yourself. The others will be automatically set by the HTTP request library.

The resulting JSON has this form:

{
 "version": "1.0",
 "encoding": "UTF-8",
 "feed": {
  "xmlns$exif": "http://schemas.google.com/photos/exif/2007",
  "xmlns": "http://www.w3.org/2005/Atom",
  "xmlns$gphoto": "http://schemas.google.com/photos/2007",
  "xmlns$media": "http://search.yahoo.com/mrss/",
  "xmlns$openSearch": "http://a9.com/-/spec/opensearchrss/1.0/",
  "id": {
   "$t": "https://picasaweb.google.com/data/feed/api/user/default/albumid/5878619262205595681"
  },
  "updated": {
   "$t": "2013-05-16T16:51:37.897Z"
  },
  "category": [
   {
    "scheme": "http://schemas.google.com/g/2005#kind",
    "term": "http://schemas.google.com/photos/2007#album"
   }
  ],
  "title": {
   "$t": "Profile Photos",
   "type": "text"
  },
  "subtitle": {
   "$t": "Album for profile photos",
   "type": "text"
  },
  "rights": {
   "$t": "public",
   "type": "text"
  },
  "icon": {
   "$t": "https://lh3.googleusercontent.com/-GQEmJ0Fn740/UZUNEp2IkCE/AAAAAAAAAJ4/zzlbQ8Dcgow/s160-c/ProfilePhotos02.jpg"
  },
  "link": [
   {
    "rel": "http://schemas.google.com/g/2005#feed",
    "type": "application/atom+xml",
    "href": "https://picasaweb.google.com/data/feed/api/user/110180137313777559136/albumid/5878619262205595681?alt=json"
   },
   {
    "rel": "http://schemas.google.com/g/2005#post",
    "type": "application/atom+xml",
    "href": "https://picasaweb.google.com/data/feed/api/user/110180137313777559136/albumid/5878619262205595681?alt=json"
   },
   {
    "rel": "http://schemas.google.com/g/2005#resumable-create-media",
    "type": "application/atom+xml",
    "href": "https://picasaweb.google.com/data/upload/resumable/media/create-session/feed/api/user/110180137313777559136/albumid/5878619262205595681?alt=json"
   },
   {
    "rel": "alternate",
    "type": "text/html",
    "href": "https://picasaweb.google.com/110180137313777559136/ProfilePhotos02"
   },
   {
    "rel": "http://schemas.google.com/photos/2007#slideshow",
    "type": "application/x-shockwave-flash",
    "href": "https://static.googleusercontent.com/external_content/picasaweb.googleusercontent.com/slideshow.swf?host=picasaweb.google.com&RGB=0x000000&feed=https://picasaweb.google.com/data/feed/api/user/110180137313777559136/albumid/5878619262205595681?alt%3Drss"
   },
   {
    "rel": "http://schemas.google.com/photos/2007#report",
    "type": "text/html",
    "href": "https://picasaweb.google.com/lh/reportAbuse?uname=110180137313777559136&aid=5878619262205595681"
   },
   {
    "rel": "http://schemas.google.com/acl/2007#accessControlList",
    "type": "application/atom+xml",
    "href": "https://picasaweb.google.com/data/feed/api/user/110180137313777559136/albumid/5878619262205595681/acl?alt=json"
   },
   {
    "rel": "self",
    "type": "application/atom+xml",
    "href": "https://picasaweb.google.com/data/feed/api/user/110180137313777559136/albumid/5878619262205595681?alt=json&start-index=1&max-results=1000"
   }
  ],
  "author": [
   {
    "name": {
     "$t": "Chris Johnson"
    },
    "uri": {
     "$t": "https://picasaweb.google.com/110180137313777559136"
    }
   }
  ],
  "generator": {
   "$t": "Picasaweb",
   "version": "1.00",
   "uri": "http://picasaweb.google.com/"
  },
  "openSearch$totalResults": {
   "$t": 2
  },
  "openSearch$startIndex": {
   "$t": 1
  },
  "openSearch$itemsPerPage": {
   "$t": 1000
  },
  "gphoto$id": {
   "$t": "5878619262205595681"
  },
  "gphoto$name": {
   "$t": "ProfilePhotos02"
  },
  "gphoto$location": {
   "$t": ""
  },
  "gphoto$access": {
   "$t": "public"
  },
  "gphoto$timestamp": {
   "$t": "1368722733000"
  },
  "gphoto$numphotos": {
   "$t": 2
  },
  "gphoto$numphotosremaining": {
   "$t": 1098
  },
  "gphoto$bytesUsed": {
   "$t": "287957"
  },
  "gphoto$user": {
   "$t": "110180137313777559136"
  },
  "gphoto$nickname": {
   "$t": "Chris Johnson"
  },
  "gphoto$commentingEnabled": {
   "$t": "true"
  },
  "gphoto$commentCount": {
   "$t": 0
  },
  "gphoto$albumType": {
   "$t": "ProfilePhotos"
  },
  "gphoto$allowPrints": {
   "$t": "true"
  },
  "gphoto$allowDownloads": {
   "$t": "true"
  },
  "entry": [
   {
    "id": {
     "$t": "https://picasaweb.google.com/data/entry/api/user/110180137313777559136/albumid/5878619262205595681/photoid/5878619375845134402?alt=json"
    },
    "published": {
     "$t": "2013-05-16T16:45:33.000Z"
    },
    "updated": {
     "$t": "2013-05-16T16:51:37.897Z"
    },
    "category": [
     {
      "scheme": "http://schemas.google.com/g/2005#kind",
      "term": "http://schemas.google.com/photos/2007#photo"
     }
    ],
    "title": {
     "$t": "screenshot.png",
     "type": "text"
    },
    "summary": {
     "$t": "",
     "type": "text"
    },
    "content": {
     "type": "image/png",
     "src": "https://lh5.googleusercontent.com/-pqzKhdeNmeQ/UZUNLRL6UEI/AAAAAAAAAKY/J93RideMY8c/screenshot.png"
    },
    "link": [
     {
      "rel": "http://schemas.google.com/g/2005#feed",
      "type": "application/atom+xml",
      "href": "https://picasaweb.google.com/data/feed/api/user/110180137313777559136/albumid/5878619262205595681/photoid/5878619375845134402?alt=json"
     },
     {
      "rel": "alternate",
      "type": "text/html",
      "href": "https://picasaweb.google.com/110180137313777559136/ProfilePhotos02#5878619375845134402"
     },
     {
      "rel": "http://schemas.google.com/photos/2007#canonical",
      "type": "text/html",
      "href": "https://picasaweb.google.com/lh/photo/ZU_8PV_Y7C538B9YyR9JFdMTjNZETYmyPJy0liipFm0"
     },
     {
      "rel": "self",
      "type": "application/atom+xml",
      "href": "https://picasaweb.google.com/data/entry/api/user/110180137313777559136/albumid/5878619262205595681/photoid/5878619375845134402?alt=json"
     },
     {
      "rel": "edit",
      "type": "application/atom+xml",
      "href": "https://picasaweb.google.com/data/entry/api/user/110180137313777559136/albumid/5878619262205595681/photoid/5878619375845134402/6?alt=json"
     },
     {
      "rel": "edit-media",
      "type": "image/jpeg",
      "href": "https://picasaweb.google.com/data/media/api/user/110180137313777559136/albumid/5878619262205595681/photoid/5878619375845134402/6"
     },
     {
      "rel": "media-edit",
      "type": "image/jpeg",
      "href": "https://picasaweb.google.com/data/media/api/user/110180137313777559136/albumid/5878619262205595681/photoid/5878619375845134402/6"
     },
     {
      "rel": "http://schemas.google.com/photos/2007#report",
      "type": "text/html",
      "href": "https://picasaweb.google.com/lh/reportAbuse?uname=110180137313777559136&aid=5878619262205595681&iid=5878619375845134402"
     }
    ],
    "gphoto$id": {
     "$t": "5878619375845134402"
    },
    "gphoto$version": {
     "$t": "6"
    },
    "gphoto$position": {
     "$t": 999998.0
    },
    "gphoto$albumid": {
     "$t": "5878619262205595681"
    },
    "gphoto$access": {
     "$t": "public"
    },
    "gphoto$width": {
     "$t": "512"
    },
    "gphoto$height": {
     "$t": "512"
    },
    "gphoto$size": {
     "$t": "132388"
    },
    "gphoto$client": {
     "$t": "es-profile"
    },
    "gphoto$checksum": {
     "$t": ""
    },
    "gphoto$timestamp": {
     "$t": "1368722733000"
    },
    "gphoto$imageVersion": {
     "$t": "166"
    },
    "gphoto$commentingEnabled": {
     "$t": "true"
    },
    "gphoto$commentCount": {
     "$t": 0
    },
    "gphoto$streamId": [
     {
      "$t": "shared_group_5878619375845134402"
     }
    ],
    "gphoto$license": {
     "$t": "ALL_RIGHTS_RESERVED",
     "id": 0,
     "name": "All Rights Reserved",
     "url": ""
    },
    "gphoto$shapes": {
     "faces": "done"
    },
    "exif$tags": {
     "exif$imageUniqueID": {
      "$t": "e0427ec517da0ee9da6a3f6baebaf558"
     }
    },
    "media$group": {
     "media$content": [
      {
       "url": "https://lh5.googleusercontent.com/-pqzKhdeNmeQ/UZUNLRL6UEI/AAAAAAAAAKY/J93RideMY8c/screenshot.png",
       "height": 512,
       "width": 512,
       "type": "image/png",
       "medium": "image"
      }
     ],
     "media$credit": [
      {
       "$t": "Chris Johnson"
      }
     ],
     "media$description": {
      "$t": "",
      "type": "plain"
     },
     "media$keywords": {},
     "media$thumbnail": [
      {
       "url": "https://lh5.googleusercontent.com/-pqzKhdeNmeQ/UZUNLRL6UEI/AAAAAAAAAKY/J93RideMY8c/s72/screenshot.png",
       "height": 72,
       "width": 72
      },
      {
       "url": "https://lh5.googleusercontent.com/-pqzKhdeNmeQ/UZUNLRL6UEI/AAAAAAAAAKY/J93RideMY8c/s144/screenshot.png",
       "height": 144,
       "width": 144
      },
      {
       "url": "https://lh5.googleusercontent.com/-pqzKhdeNmeQ/UZUNLRL6UEI/AAAAAAAAAKY/J93RideMY8c/s288/screenshot.png",
       "height": 288,
       "width": 288
      }
     ],
     "media$title": {
      "$t": "screenshot.png",
      "type": "plain"
     }
    }
   },
   {
    "id": {
     "$t": "https://picasaweb.google.com/data/entry/api/user/110180137313777559136/albumid/5878619262205595681/photoid/5878619210452116082?alt=json"
    },
    "published": {
     "$t": "2013-05-16T16:44:54.000Z"
    },
    "updated": {
     "$t": "2013-05-16T16:51:17.700Z"
    },
    "category": [
     {
      "scheme": "http://schemas.google.com/g/2005#kind",
      "term": "http://schemas.google.com/photos/2007#photo"
     }
    ],
    "title": {
     "$t": "screenshot.png",
     "type": "text"
    },
    "summary": {
     "$t": "",
     "type": "text"
    },
    "content": {
     "type": "image/png",
     "src": "https://lh5.googleusercontent.com/-fWLorH-xwIQ/UZUNBpDJInI/AAAAAAAAAJk/4Ns2XhPp8xo/screenshot.png"
    },
    "link": [
     {
      "rel": "http://schemas.google.com/g/2005#feed",
      "type": "application/atom+xml",
      "href": "https://picasaweb.google.com/data/feed/api/user/110180137313777559136/albumid/5878619262205595681/photoid/5878619210452116082?alt=json"
     },
     {
      "rel": "alternate",
      "type": "text/html",
      "href": "https://picasaweb.google.com/110180137313777559136/ProfilePhotos02#5878619210452116082"
     },
     {
      "rel": "http://schemas.google.com/photos/2007#canonical",
      "type": "text/html",
      "href": "https://picasaweb.google.com/lh/photo/M03wpjhc_Gh_LW4NdrSueNMTjNZETYmyPJy0liipFm0"
     },
     {
      "rel": "self",
      "type": "application/atom+xml",
      "href": "https://picasaweb.google.com/data/entry/api/user/110180137313777559136/albumid/5878619262205595681/photoid/5878619210452116082?alt=json"
     },
     {
      "rel": "edit",
      "type": "application/atom+xml",
      "href": "https://picasaweb.google.com/data/entry/api/user/110180137313777559136/albumid/5878619262205595681/photoid/5878619210452116082/4?alt=json"
     },
     {
      "rel": "edit-media",
      "type": "image/jpeg",
      "href": "https://picasaweb.google.com/data/media/api/user/110180137313777559136/albumid/5878619262205595681/photoid/5878619210452116082/4"
     },
     {
      "rel": "media-edit",
      "type": "image/jpeg",
      "href": "https://picasaweb.google.com/data/media/api/user/110180137313777559136/albumid/5878619262205595681/photoid/5878619210452116082/4"
     },
     {
      "rel": "http://schemas.google.com/photos/2007#report",
      "type": "text/html",
      "href": "https://picasaweb.google.com/lh/reportAbuse?uname=110180137313777559136&aid=5878619262205595681&iid=5878619210452116082"
     }
    ],
    "gphoto$id": {
     "$t": "5878619210452116082"
    },
    "gphoto$version": {
     "$t": "4"
    },
    "gphoto$position": {
     "$t": 999999.0
    },
    "gphoto$albumid": {
     "$t": "5878619262205595681"
    },
    "gphoto$access": {
     "$t": "public"
    },
    "gphoto$width": {
     "$t": "512"
    },
    "gphoto$height": {
     "$t": "512"
    },
    "gphoto$size": {
     "$t": "155569"
    },
    "gphoto$client": {
     "$t": "es-profile"
    },
    "gphoto$checksum": {
     "$t": ""
    },
    "gphoto$timestamp": {
     "$t": "1368722694000"
    },
    "gphoto$imageVersion": {
     "$t": "153"
    },
    "gphoto$commentingEnabled": {
     "$t": "true"
    },
    "gphoto$commentCount": {
     "$t": 0
    },
    "gphoto$streamId": [
     {
      "$t": "shared_group_5878619210452116082"
     }
    ],
    "gphoto$license": {
     "$t": "ALL_RIGHTS_RESERVED",
     "id": 0,
     "name": "All Rights Reserved",
     "url": ""
    },
    "gphoto$shapes": {
     "faces": "done"
    },
    "exif$tags": {
     "exif$imageUniqueID": {
      "$t": "e0427ec517da0ee9da6a3f6baebaf558"
     }
    },
    "media$group": {
     "media$content": [
      {
       "url": "https://lh5.googleusercontent.com/-fWLorH-xwIQ/UZUNBpDJInI/AAAAAAAAAJk/4Ns2XhPp8xo/screenshot.png",
       "height": 512,
       "width": 512,
       "type": "image/png",
       "medium": "image"
      }
     ],
     "media$credit": [
      {
       "$t": "Chris Johnson"
      }
     ],
     "media$description": {
      "$t": "",
      "type": "plain"
     },
     "media$keywords": {},
     "media$thumbnail": [
      {
       "url": "https://lh5.googleusercontent.com/-fWLorH-xwIQ/UZUNBpDJInI/AAAAAAAAAJk/4Ns2XhPp8xo/s72/screenshot.png",
       "height": 72,
       "width": 72
      },
      {
       "url": "https://lh5.googleusercontent.com/-fWLorH-xwIQ/UZUNBpDJInI/AAAAAAAAAJk/4Ns2XhPp8xo/s144/screenshot.png",
       "height": 144,
       "width": 144
      },
      {
       "url": "https://lh5.googleusercontent.com/-fWLorH-xwIQ/UZUNBpDJInI/AAAAAAAAAJk/4Ns2XhPp8xo/s288/screenshot.png",
       "height": 288,
       "width": 288
      }
     ],
     "media$title": {
      "$t": "screenshot.png",
      "type": "plain"
     }
    }
   }
  ]
 }
}

In this dictionary, you can (maybe) see that there are two images listed in the feed/entry array. Much like album, we want from each element in the entry array title/$t and gphoto$id/$t. We present the titles in our list view and issue future requests on individual images using the identifiers.

Fetching a picture in an album

Fetching an image is a little less direct. First we have to issue a GET request to get the image’s download URL. We can send along various parameters indicating what resolution of the image we want. Perhaps we just need a thumbnail. No sense sending the original image down the wire. However, that’s what we’ll do today. You can explore the sizing parameters on your own.

We issue a GET request to the following URL:

https://picasaweb.google.com/data/feed/api/user/default/albumid/ALBUMID/photoid/PHOTOID?alt=json&prettyprint=true&imgmax=d

You’ll need the Authorization header as before.

The JSON that gets sent back in response is similar to those above, but it only contains information about the identifier picture. We can get at the download URL via feed/media$group/media$content. The 0th element of this array is a dictionary. Key “url” leads us to the download link.

Then we issue an HTTP GET request using the download URL. Include the Authorization header.

Uploading a picture to an album

The quickest way to upload a JPEG image is to issue a POST request with a couple of descriptive headers. Content-Length tells the size of JPEG byte array payload attached as the body of the request. Content-Type tells the server what kind of MIME type is attached, which is image/jpeg in our case.

You’ll also need the usual Authorization header and an identifier of the album to upload to.

See the following sections on how to convert an image to a byte array and attach it as a payload to a POST request.

Issuing HTTP requests on iOS

Here’s a snippet of my code where I issue an HTTP GET request to retrieve the JSON metadata for a given album. This code assumes the selected album is stored in a property.

NSURL *url = [[NSURL alloc] initWithString:[NSString stringWithFormat:@"https://picasaweb.google.com/data/feed/api/user/default/albumid/%@?alt=json&prettyprint=true", self.selectedAlbum.identifier]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"GET"];
[request setValue:[NSString stringWithFormat:@"Bearer %@", ACCESS_TOKEN] forHTTPHeaderField:@"Authorization"];

// Issue request and catch result.
NSError *error = nil;
NSURLResponse *response = [[NSURLResponse alloc] init];
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

// Turn result into a JSON dictionary.
NSDictionary *result = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];

And here’s a POST request, which takes the image from a camera popup, converts it to a JPEG byte array, and then uploads the image to a given album:

UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
NSData *imageAsData = UIImageJPEGRepresentation(image, 0.5);

NSURL *url = [[NSURL alloc] initWithString:[NSString stringWithFormat:@"https://picasaweb.google.com/data/feed/api/user/default/albumid/%@?alt=json&prettyprint=true", self.selectedAlbum.identifier]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:[NSString stringWithFormat:@"Bearer %@", ACCESS_TOKEN] forHTTPHeaderField:@"Authorization"];
[request setValue:@"image/jpeg" forHTTPHeaderField:@"Content-Type"];
[request setValue:[NSString stringWithFormat:@"%d", imageAsData.length] forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:imageAsData];

// Issue request and catch result.
NSError *error = nil;
NSURLResponse *response = [[NSURLResponse alloc] init];
[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

I ignore the result. Probably a bad idea.

Issuing HTTP requests on Android

Earlier in the semester, we used Apache’s HttpClient class to make HTTP requests. I found it a little simpler to use HttpUrlConnection instead. Here’s a GET request for grabbing the JSON for a particular album:

try {
  URL url = new URL("https://picasaweb.google.com/data/feed/api/user/default/albumid/" + albumID + "?alt=json&prettyprint=true");
  HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  connection.setRequestMethod("GET");
  connection.addRequestProperty("Authorization", "Bearer " + Constants.ACCESS_TOKEN);
  InputStream is = connection.getInputStream();
  int responseCode = connection.getResponseCode();
  Log.d("FOO", String.format("Response code: %d", responseCode));

  BufferedReader in = new BufferedReader(new InputStreamReader(is));
  StringBuffer buffer = new StringBuffer();
  String line = in.readLine();
  while (line != null) {
    Log.d("FOO", line);
    buffer.append(line);
    line = in.readLine();
  }
  in.close();

  JSONObject json = new JSONObject(buffer.toString());
  // deconstruct json
} catch (MalformedURLException e) {
  e.printStackTrace();
} catch (IOException e) {
  e.printStackTrace();
} catch (JSONException e) {
  e.printStackTrace();
}

Building a JPEG byte array from a Bitmap and pushing it up to Picasa Web via a POST request can be done with the following code:

try {
  URL url = new URL("https://picasaweb.google.com/data/feed/api/user/default/albumid/" + albumID + "?alt=json&prettyprint=true");
  HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  connection.setRequestMethod("POST");
  connection.setDoOutput(true);
  connection.addRequestProperty("Authorization", "Bearer " + Constants.ACCESS_TOKEN);
  connection.addRequestProperty("Content-Type", "image/jpeg");

  ByteArrayOutputStream out = new ByteArrayOutputStream();
  bitmap.compress(Bitmap.CompressFormat.JPEG, 50, out);
  connection.addRequestProperty("Content-Length", "" + out.size());

  OutputStream os = connection.getOutputStream();
  os.write(out.toByteArray());

  int responseCode = connection.getResponseCode();
  Log.d("FOO", String.format("Response code: %d", responseCode));

  InputStream is = connection.getInputStream();
  BufferedReader in = new BufferedReader(new InputStreamReader(is));
  StringBuffer buffer = new StringBuffer();
  String line = in.readLine();
  while (line != null) {
    Log.d("FOO", line);
    buffer.append(line);
    line = in.readLine();
  }
  in.close();
} catch (MalformedURLException e) {
  e.printStackTrace();
} catch (IOException e) {
  e.printStackTrace();
}

Whew.

Haiku

Our dream: abstraction
It’s like eating lint
I prefer concrete