简体   繁体   中英

How to only obtain list of names from facebook - using RoR, fb_graph gem

Currently, I am using the fb_graph gem to obtain a list of friends:

FbGraph::User.me(fb_token).friends

However, this returns me a massive array with lots of fields, such as name, gender, languages, etc. I want to filter all the fields and have obtain a list of friends.

I could loop through the list extracting the name, however, I was looking for something more efficient.

I was thinking something like:

FbGraph::User.me(fb_token).friends(:name)

Anyone know how to do this? The link to the gem is https://github.com/nov/fb_graph

Thanks!

Is your goal just to end up with the array of names for subsequent use, or is it to avoid retrieving so much data from FB?

You can get the array of names with something like

FbGraph::User.me(fb_token).friends.map {|f| f.name }

That should produce the end result you want. It won't reduce the amount of data pulled from FB, though - unfortunately i haven't used fb_graph enough to help there.

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