简体   繁体   中英

How to get my Facebook friends with OmniAuth in Rails?

I have a simple Rails app where I can log in with using Facebook through OmniAuth.

Is there any way to obtain my Facebook friends with using OmniAuth Facebook gem? Do I need to use any other gems for that? (if so, which ones are the best ones - the most updated/etc).

You can also use the koala gem which works well Facebook graph api.

@graph = Koala::Facebook::API.new(oauth_access_token)
friends = @graph.get_connections("me", "friends")

Try using gem 'fb_graph' for it. Check the link for it https://github.com/nov/fb_graph

You can get your fb friends by

@fb_friends = FbGraph::User.me(USER-FB-ACCESS-Token).friends

Here, USER-FB-ACCESS-Token is the access token that one user will will get after connecting to facebook via omniauth facebook.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM