bdunagan

fill the void - bdunagan

06 Sep 2014
Ruby integration with YouTube API v3

For Retrospect, we host around 80 tutorial videos on YouTube. I mirror the videos on the site as well under Tutorials. When I added them to the site, I used Atom feeds (YouTube API v2) to gather the list of videos. On Tuesday, those ceased to work (a bit before their official April 2015 EOL date), so I migrated the site to YouTube API v3.

Migrating was not straight-forward. No more Atom or RSS feeds. All queries now need to be authenticated, understandable as YouTube will now be able to track usage and enforce quotas. Google Developers Console issues multiple types of API keys, including a server key and a browser key. The server key makes the most sense for my usage; the server fetches the video listings on launch and caches them.

However, the server key requires an IP restriction. We run retrospect.com on Heroku, with dynamic IP addresses (static IP addresses require a paid add-on), and I had no luck finding a CIDR address range for Heroku apps. The alternative is the browser key. It is supposed to be used by a web browser and requires a referral restriction. So, I created a browser key and inject a referer.

YouTube API v3 is different from the Atom feeds, so I’ll walk through how to accomplish typical queries with curl and ruby. (Google also has an excellent API Explorer app to try as well.)

Previous LinkedIn Twitter GitHub Email Next