简体   繁体   中英

How to get friends profile pics using FQL query using FBGraph-API

I would like to know do I have an option to set pics width and height while requesting. Somebody suggested me to use the below query to achieve this behavior:

SELECT id, width, height, url, is_silhouette, real_width, real_height FROM profile_pic
 WHERE id=me() AND width=155 AND height=50

Is this the correct process? According to my requirement I need to display profile pics in a table as in the attached screenshot with 155 as width and 50 as height.

我的朋友清单

Thanks in Advance

FQL to get list of facebook friends information & their Pics

NSString *query = @"SELECT uid,name,first_name,last_name,pic_square FROM user WHERE uid IN (";
query = [query stringByAppendingFormat:@"SELECT uid2 FROM friend WHERE uid1 = %@)",userid];
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                query, @"query",
                                nil];
[_facebook requestWithMethodName: @"fql.query" 
                       andParams: params
                   andHttpMethod: @"POST" 
                     andDelegate:self]; 

You will get responce in follwing method

  -(void)request:(FBRequest *)request didLoad:(id)result 

For Example

{
    "first_name" =User;
    "last_name" = R;
    name = "User R";
    "pic_square" = "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash2/.jpg";
    uid = 595sd1;
     }
 {},{} etc

Hope this helps!

Another way is

Get the id (or the nick) of the user, and get the picture from https://graph.facebook.com/idOrNick/picture

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture", id]];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:data];
UIImageView *imgView = [[UIImageView alloc]init];
imgView.image = image;

And for size

PICTURE SIZES: square (50×50)

small (50 pixels wide, variable height)

large (about 200 pixels wide, variable height)

and for applying this type of size you have to append it end of the URL

for example

http://graph.facebook.com/ "id or Nick"/picture?type=large. [small/square/large]

Here is a code , which can help you to get friend's profile picture.

  1. Get the Id of a friend from the FBGraph API eg

      NSString *id = @"505326797"; 
  2. Then paste the following code ...

      NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture",id]]; 
  3. This is the way you can get the exact url of friend's picture ,, use this either in Asynchronous Image View or somewhere else.....

Perhaps it will help you...

Yes. Your code is correct. This will get version of your picture that is approx. 155 x 50px.

If you wanted to get a user's friend's pictures, use this query :

 SELECT id, width, height, url, is_silhouette, real_width, real_height  
     FROM profile_pic
         WHERE id IN (SELECT uid1 FROM friend WHERE uid2=me()) AND width=155 AND height=50

使用Graph API字段扩展方法-

graph.facebook.com/USER_ID?fields=friends.fields(picture.height(50).width(155))

I'm looking for the answer to this question, too. Finally I think this call is the best:

http://graph.facebook.com/me/friends?fields=name,picture.height(200).width(200)

You can also replace the 'me' with a certain id.

As per the docs https://developers.facebook.com/docs/reference/api/using-pictures/ , there is a simpler way to do it. The direct URL to get customized image from facebook is:

https://graph.facebook.com/<USER_ID>/picture?width=<WIDTH>&height=<HEIGHT>

I understand the question is about using GraphAPI to get the URL but why make one extra call when you can give the image src URL directly.

<img src="https://graph.facebook.com/${ID}/picture?width=${customwidth}&height=$customheight" />

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