2

I can't seem to properly retrieve a user's profile picture using the current iOS graph method.

My call: self.pictureRequest = [facebook requestWithGraphPath:@"me/picture" andDelegate:self];

What I do with the result:

-(void)request:(FBRequest *)request didLoad:(id)result{
    if(request == self.pictureRequest){
        UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
        image.image = [UIImage imageWithData:result];
        [self.view addSubview:image];
        NSLog("result is %@", result);
    }

So I'm just trying to get the profile picture right now. Result shows up as null in the console. I guess this means I'm not actually getting a result? (I tried if(result) NSLog(@"got a result") but it doesn't return, so I'm guessing a result isn't being sent back by fb?)

Any ideas? I also looked up a similar problem here but not sure what they do differently: Problem getting Facebook pictures via iOS

Community
  • 1
  • 1
user339946
  • 5,961
  • 9
  • 52
  • 97

3 Answers3

2

well I can retrieve the user pic and other info like this .. try it

- (void)fetchUserDetails {
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   @"SELECT uid, name, pic, email FROM user WHERE uid=me()", @"query",nil];

    [fb requestWithMethodName:@"fql.query"
                                     andParams:params
                                 andHttpMethod:@"POST"
                                   andDelegate:self];


}//Call this function after the facebook didlogin

and in request didLoad:

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

    if([request.url rangeOfString:@"fql.query"].location !=NSNotFound)
    {
        if ([result isKindOfClass:[NSArray class]] && [result count]>0) {
            result = [result objectAtIndex:0];
        }
        if ([result objectForKey:@"name"]) {

            self.fbUserName = [result objectForKey:@"name"];

           // Get the profile image
            UIImage *fbimage = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[result objectForKey:@"pic"]]]];
}
Malek_Jundi
  • 6,140
  • 2
  • 27
  • 36
0

If you want to get the picture URL using requestWithGraph path (instead of requestWithMethodName like @Malek_Jundi provides) then see my answer here:

iOS Facebook Graph API Profile picture link

Community
  • 1
  • 1
Joel
  • 15,654
  • 5
  • 37
  • 60
0

You can also get fb profile picture url by,

NSString *userFbId;
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture", userFbId]];

NSData *imageData = [[NSData alloc] initWithContentsOfURL:url];
self.userProfileImage.image = [UIImage imageWithData:imageData];
QUserS
  • 512
  • 5
  • 13