Tuesday, October 20, 2015

Setting up this feed

When I set out to create this simple personal site a few days ago, I knew I wanted the blog and gallery to be "built-in", staying on the same page without redirecting to another service/subdomain. Given that problem, three quick solutions come to mind:
  1. Use a CMS such as Wordpress, Ghost, Django, etc.
  2. Build a simple back-end service that supports the bare minimum I wanted
  3. Use a hosted platform with a lower-complexity API
Although Wordpress and others are good, time-tested options with lots of support, right off the bat I knew they were overkill for what I wanted and can often be more trouble to setup and theme correctly than if you were to start from scratch. No-go. Building a back-end service was tempting, though it would've escalated the complexity by an order of magnitude and require a greater time investment, so I ended up at option #3. All I knew was that I wanted something that didn't require a complex authentication flow such as OAuth since these would be public items anyway.

I decided to start with the gallery, and some cursory Google searches found me browsing the Picasa Web Albums Data API, which appeared to be just what I needed: An easy auth (or no auth in this case) service that allows me to pull photos from a public, hosted album. To top it off, I found a small Angular library with a directive and service for pulling those public photos -- success! Turns out, all you need to do is issue a GET request to the Picasa service with your userId and albumId, which you can get by checking the Network requests for that album on the actual Picasa platform (see below). After that, the query parameters provided all the configuration I needed. I used Masonry to tile up the photos and with zero configuration (seriously, there's no controller for the gallery state!) and very little styling, I was good to go. The end result was responsive and good looking with a very minimal code footprint. See your yourself!

You can also get your userId from your public Google+ profile!

Blogging turned out to be much a similar matter. I explored some blogging platforms such as Medium and others, though their APIs were either overly-complex or non-existent. Blogger, a no-frills blogging platform ironically also run by Google, unsurprisingly turned out to be very similar to the Picasa API with just as awesome documentation. This one required auth, though only an API key when retrieving public blog information as opposed to an OAuth flow for private data. I re-used the same service/directive setup used by the Picasa component and changed it slightly to work with Blogger. Once again, there was no controller-specific code needed and everything was kept very simple, the result of which you are reading right now.

I still need to work out a couple of issues such as the initial page render of the gallery or the mystery of the missing prevPageToken in version 3 of the Blogger API but those remain for another day.