Forward Slash.

a codetrip to the wild west

Setting Up Heroku & Why the FB API Is Kind of a Pain

Ahh, those days when you have a brilliant (or not so brilliant) idea and want to make a cool app. You set up Heroku so other people can use it, make some api requests to start gathering data, and eagerly start coding, right? …More like, you realize Facebook requires you to apply for permission if you want to use anything more than the barebones data they give you default access to (a process which they say can take up to 14 business days)…so that app you wanted to build overnight turns into a woeful blog post about what little you’ve been able to accomplish thus far, which is this, and only this: (UPDATE: I built the app with twitter!) http://your-vocabulary-sucks.herokuapp.com/

What I wanted to do was pull all of a user’s Facebook posts and tally up their most commonly used words to see not only how sophisticated their vocabulary is, but maybe how egotistical they are, how angry, and other such nonsense. Maybe chart that information using Chart.js or some other cool library. Now we’ll never know, at least until Facebook approves my application that is.

Okay, let’s get started with Heroku, shall we? First if you don’t already have an account, sign up here: https://dashboard.heroku.com/apps

Additionally, you need a web app in order to deploy to Heroku, so if you don’t have one, you can do a quick rails new and set up an index.html.erb page so there’s something to display. Keep in mind that Heroku uses postgres, but creating a new rails app by default gives you sqlite3 in your gemfile. Instead, you should install postgres on your computer and run

1
rails new [appname] --database=postgresql

that way you’re running the same database system in development and production. If you don’t have this set up correctly, you will get an error deploying to heroku or when you try to view your app locally, or both.

Also make sure your project is a git repository and you’ve been pushing all your changes to github (just to be safe), you’ll also be using git to push to Heroku. Once you have a Heroku account you need to install their toolbelt, after which you can login in your terminal by typing

1
heroku login

You’ll be prompted for your credentials which hopefully you remember. Then in order to create a Heroku app, you can run

1
heroku create [optional name]

If you don’t pass it a name, Heroku will automatically generally something silly like limitless-peak-5480, which is actually pretty snazzy if that’s what you’re into. If you accidentally forget to pass in a name, don’t worry! You can change the name using

1
heroku apps:rename [newname]

To deploy code, simply run

1
git push heroku master

and you’re golden. If the push works but your Heroku app isn’t working for some reason you can type

1
heroku logs

for a more detailed view of what exactly is happening to help you debug. That’s all I have today, hopefully I’ll get the right Facebook api permissions soon so I can actually do a more interesting post!