Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the picture of Facebook User using Koala gem?

I am trying to fetch the picture of a Facebook user's friends using their facebook ids, but using the following code returns nil instead of the picture url...

The code I am using is as follows:

picture_url = @user.get_picture("1000000111")

where @user is the Graph API Object made using Facebook authentication...

What is missing in this code?? Thanks in advance.

like image 1000
Apoorv Saxena Avatar asked Mar 20 '11 08:03

Apoorv Saxena


2 Answers

To get all facebook friend images in ruby on rails. you can use Koala gem https://github.com/arsduo/koala

It has got nice doumentation

To get the facebbok friend 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 will have to send request for each friend.

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

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

To Write 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())")
like image 113
Puneeth Avatar answered Sep 19 '22 08:09

Puneeth


You can also get all friends with their pictures using get_connection() as follows

friends = @graph.get_connections("me", "friends?fields=id,name,picture.type(large)")
like image 42
Moustafa Samir Avatar answered Sep 21 '22 08:09

Moustafa Samir