Reputation: 1006
I am using FB login on my mobile app because I don't want users to create an account and enter redundant information like name, age, city, and so on. The user gives access to the app on the mobile device, and the device receives a FB access token.
I was wondering if I could send the same access token to my Ruby on Rails server through its REST API and then get the server to access user's profile and retrieve all information (and return it to client later).
Any information on how to go about it would be helpful. Thanks
(PS. Another approach I could take was to retrieve user info on the client, and then ask the user to create a password. This would mean that the server is FB-agnostic, but the user will have to remember one more password, and log in using that every time he uses the app. I wanted to avoid that.)
Upvotes: 2
Views: 1445
Reputation: 1006
I found a way of accessing Facebook Graph API from the Rails server using the access token. I used the gem fb_graph.
I made sure I was sending the fb_ID
with the access token from the client to the server.
Then used the fb_ID
along with the access token to get the user
user = FbGraph::User.fetch(fb_ID, :access_token => ACCESS_TOKEN)
The user
object returned all information that I needed - name, email, gender, birthday and city.
Upvotes: 4