Authentication using Facebook via Rails API

android, facebook, omniauth, ruby, ruby-on-rails

Solution

This can be done using the fb_graph gem (not fbgraph!).

You can just add it to your gemfile and do

user = FbGraph::User.me(token).fetch

where `token` is the oauth token you got by using, for example, the Facebook SDK on Android. `user.email` will be the user's email address (if you set up the necessary permissions).

You can use this URL for testing:

https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri=https://www.facebook.com/connect/login_success.html&response_type=token

Problem

Users of my Rails app can authenticate in one of these 2 manners: - Using their Facebook account - Using our own authentication I'm using Facebook SDK on Android and `devise` and `omniauth` on Rails. How do I authenticate against my Rails app on Android so I can then fetch the information I need from the server? NB: I've noticed this question is getting a fair amount of views recently. Please don't follow the advice given in this thread too closely -- the web moves fast and it dates from 3 years ago!

Original source