How to get Facebook user image using Koala gem?

I'm trying to get an image of friends of Facebook users with their facebook ids, but using the following code returns nil instead of the url image ...

The code I use is as follows:

picture_url = @user.get_picture("1000000111") 

where @user is a Graph API object created using Facebook Authentication ...

What is missing in this code? Thanks in advance.

+6
ruby-on-rails facebook-graph-api
source share
6 answers

I do not know about Koala, but if you ask for the user ID (in the form of graph.facebook.com/odedharth/picture ), you can get it.

+2
source share

Get all the images of facebook friends in ruby ​​on rails. you can use koala stone https://github.com/arsduo/koala

He got a nice favor

To get a friend facebbok you can use

 @graph = Koala::Facebook::API.new(oauth_access_token) friends = @graph.get_connections("me", "friends") friends.each do |f| f[:image]= @graph.get_picture(f["id"]) end 

But this method will take too much time, because you have to send a request for each friend.

To avoid this, you can use the REST API, which supports koala,

 @rest = Koala::Facebook::API.new(oauth_access_token) @rest.fql_query(my_fql_query) @rest.fql_multiquery(fql_query_hash) # convenience method 

To record the Fql query, you can use the facebook table structure, which you can find at http://developers.facebook.com/docs/reference/fql/

to get Facebook uid, name and pic, you can use this one.

 @rest.fql_query("select uid, name, pic_square from user where uid in (select uid2 from friend where uid1 = me())") 
+13
source share

You can also get all your friends using get_connection() as follows

 friends = @graph.get_connections("me", "friends?fields=id,name,picture.type(large)") 
+12
source share

I got the image working directly using the url specified by Cody in the image tag as below

 img src="http://graph.facebook.com/10000010000001/picture" /> img src="http://graph.facebook.com/user_profile_id/picture" />
img src="http://graph.facebook.com/10000010000001/picture" /> img src="http://graph.facebook.com/user_profile_id/picture" /> 
+5
source share

Use the access token you received from oauth

 graph = Koala::Facebook::GraphAPI.new(access_token) profile_path = graph.get_picture(uid) 

To get the path, then display it

 <%= image_tag profile_path %> 

This works for me and should be for you ..

+3
source share
  USER_PROFILE_OPTIONS = { fields: %w(id first_name last_name hometown email gender birthday picture.width(320)) }.freeze @graph = Koala::Facebook::API.new(oauth_access_token) @graph.get_object('me', USER_PROFILE_OPTIONS) 

See: https://developers.facebook.com/docs/graph-api/reference/user/picture/

+1
source share

All Articles