简体   繁体   中英

iOS Facebook SDK - Retrieve Friends Profile Pictures

I'm using Facebook iOS SDK and I retrieved the user friends list. Now I have each friend name and id.

I would like to retrieve the friend profile picture, is it possible?

Thanks!

In cellForRowAtIndexPath you get id of facebook user already.....am i right??? after that in just use bellow url to get profile pic through URLRequest....

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if([friends count]!=0)
    {                        
        NSString *strurl = [[NSString alloc] initWithFormat:@"https://graph.facebook.com/%@/picture",[[friends objectAtIndex:indexPath.row] objectForKey:@"id"]];
        NSURL *url=[NSURL URLWithString:strurl];///here you can retrive the image
        [cell setObjItem:url title:[[friends objectAtIndex:indexPath.row] objectForKey:@"name"]];
        // Configure the cell.
    }
    else
    {
        NSLog(@"<<<<<<<<<<------Array Null-------->>>>>>>");
    }
    return cell;
}
 -(void)fbFriends {
        [self.facebook requestWithGraphPath:@"me/friends" andDelegate:self];
    }
    -(void)fbFriendsInfo :(NSString *)profileid {
        [self.facebook requestWithGraphPath:profileid andDelegate:self];
    }


    - (void)request:(FBRequest *)request didLoad:(id)result{
        [self hideSpinner];

        lblGender.text = [result objectForKey:@"gender"];
        lblName.text = [result objectForKey:@"name"];
        self.idi = [result objectForKey:@"id"];

        NSString *first_name = [result objectForKey:@"first_name"];
        NSString *gender = [result objectForKey:@"gender"];
        NSString *last_name = [result objectForKey:@"last_name"];
        NSString *link = [result objectForKey:@"link"];
        NSString *name = [result objectForKey:@"name"];
        NSString *updated_time = [result objectForKey:@"updated_time"];

        NSLog(@"Profile Info : \n\n%@,\n%@,\n%@,\n%@,\n%@,\n%@,\n%@",first_name,gender,idi,last_name,link,name,updated_time);

        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:AlertName message:@"Facebook Done." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
        [alert release];
    }

Use Share Controller Class and call fbFriends So u will get friends id then call fbFriendsInfo it will return all info of your friend.

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