Saturday, July 5, 2014

Make a hashtag fueled slideshow! (ruby)

I made this for my wedding so our guests could post pictures of the wedding and post them to social media and they would appear on screen in realtime. This ended up not working due to the connection abilities of our venue, but by the end of the night a laptop was setup at the exit showing the slideshow. It was still pretty cool, and now I have a way to grab photo's with a particular hashtag from the big three social media outlets, Twitter, Facebook, and Instagram. I haven't hooked this up with Google+ yet.

Each of these platforms has a ruby gem that makes the interaction with the API much simpler and intuitive. To note, I am no expert in ruby as I knew almost nothing about it a year ago and I only work on some ruby code here at Cerner. Instagram [1] and Twitter [2] have self-named gems, but the best gem I found for Facebook is called Koala [3]. To get the correct authorization tokens you need to follow the associated walk-throughs for each platform. For Twitter, there will be a reference on the gem README to create an app [4] and get the auth token from there. This documentation is pretty explicit, and was surprisingly simple to set up everything.

Twitter is slightly harder, but still pretty straight forward. You will need to login on the developer site [5], and then click on "Register Your Application." You can then create an application with the appropriate information. This will yield you a client id and client secret, but you'll still need an access token. To generate the access token, I followed Dave Olsen's advice [6] and it worked well. There may be better sources out there, but this worked for my short-term goals.

You might think Facebook being such a big company and fostering a developer culture would have better documentation and a better system for interacting with their content, but they were the hardest for me to setup. Once I finally found out how to get an access token without using redirects and a user login, everything went smoothly, but this information isn't easy to find. You'll need to create a new app [7], and then you'll be given an App ID and an App Secret. Use the App ID as the client_id and App Secret as the client_secret in this url:https://graph.facebook.com/oauth/access_token?client_id=XXXXXXXXXXXXX&client_secret=XXXXXXXXXXXXXXXX&grant_type=client_credentials. This will produce the access token you'll need for the API.

Now you are ready to plug this information into my code [8], and give it a test. I have made modifications to this code, but the basic function is the same. I have added a loop and some error handling to allow it to run continuously.

The last thing you need is a slideshow that can update in realtime. For the Mac, this was harder to find than I had imagined. I actually only found one [9] viable solution, but I have to imagine there are more. Please post in the comments if you find a better solution. There was talk of using Automator or an AppleScript, but I didn't have enough time to investigate those fully. This could also be integrated into a website, which was my goal originally, but again time was not my friend.