Reputation: 745
I need to access friends' profile pictures to display them in my game leaderboard. Most of the links to posts I found here on stackoverflow do not exist anymore. How can I access the profile pictures in a way similar to how I accessed the scores and names in the code below.
-(void)getLeaderboardInfo
{
[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:@"%llu/scores?fields=score,user", kuFBAppID] parameters:nil HTTPMethod:@"GET" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (result && !error)
{
int index = 0;
for (NSDictionary *dict in [result objectForKey:@"data"])
{
NSString *name = [[[[dict objectForKey:@"user"] objectForKey:@"name"] componentsSeparatedByString:@" "] objectAtIndex:0];
NSString *strScore = [dict objectForKey:@"score"];
// how do I get the objectforkey representing the image?
m_pLeaderboardEntries[index].pFriendName.text = [NSString stringWithFormat:@"%d. %@", index+1, name];
m_pLeaderboardEntries[index].pFriendScore.text = [NSString stringWithFormat:@"Score: %@", strScore];
// how do I add the image to my leaderboard entries?
index++;
if (index>5) {
break;
}
}
}
}];
}
The LeaderboardInstance
struct LeaderboardboardInstance
{
__unsafe_unretained UILabel *pFriendName;
__unsafe_unretained UILabel *pFriendScore;
__unsafe_unretained UIImage *profilePicture;
};
Also,
struct LeaderboardboardInstance m_pLeaderboardEntries[m_kuLeaderboardSize];
Upvotes: 1
Views: 94
Reputation: 1413
Assuming you have a Facebook user logged in and the friend's Facebook ID, this is the way to go:
NSString *imageUrl = [NSString stringWithFormat:@"http://graph.facebook.com/%@/picture?type=large", friendID];
Then you can download the image using NSURLConection
or whatever library you want.
Upvotes: 0
Reputation: 8491
Add this to your list of fields
picture.type(large)
In the result object you should then have a dictionary called picture
which contains image info including the url
of the users image
Upvotes: 1