How to get Facebook user profile picture via fbconnect in my iPhone app?

Possible duplicate:
Problem getting Facebook photos via iOS

How to get Facebook user profile picture via fbconnect in my iPhone app?

+7
ios objective-c iphone facebook fbconnect
source share
3 answers

Try a deeper look at http://developers.facebook.com/docs/api . Here is the link to userpic:

http://graph.facebook.com/000000000/picture

Where 000000000 is the ID of the registered user.

UPDATE Michael Gaylord : You can also add a type to the request to receive images of different sizes. So your query would look something like this: http://graph.facebook.com/00000000/picture?type=large for a large image. Other options are small, normal and square.

+16
source share

I think the easiest way is:

 NSString *fbuid = @"1234567890"; NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?", fbuid]]; NSData *data = [NSData dataWithContentsOfURL:url]; UIImage *profilePic = [[[UIImage alloc] initWithData:data] autorelease]; 
+16
source share

These delegate methods are used here to get the image of the user.

When you create a session, you get a delegate method called didLogin

 - (void)session:(FBSession*)session didLogin:(FBUID)uid { isLoginSuccessful = TRUE; if(isLoginCanceled == FALSE) { [self fetchUserDetails]; } } - (void)sessionDidNotLogin:(FBSession*)session { isLoginSuccessful = FALSE; isLoginCanceled = TRUE; } - (void)sessionDidLogout:(FBSession*)session { isLoginSuccessful = FALSE; isLoginCanceled = TRUE; } - (void)fetchUserDetails { NSString* fql = [NSString stringWithFormat: @"select name,sex,pic from user where uid == %lld", _session.uid]; NSDictionary* params = [NSDictionary dictionaryWithObject:fql forKey:@"query"]; [[FBRequest requestWithDelegate:self] call:@"facebook.fql.query" params:params]; } 

after calling the requestWithDelegate method, you will get a response in this method, if successful

 - (void)request:(FBRequest*)request didLoad:(id)result { if ([request.method isEqualToString:@"facebook.fql.query"]) { NSArray* users = result; NSDictionary* user = [users objectAtIndex:0]; NSLog(@"User Details %@",user); if(fbUserDetails == nil) { self.fbUserDetails = [[NSDictionary alloc] initWithDictionary:user]; } if(isLoginSuccessful) { NSString *fbUid = [NSString stringWithFormat:@"%lld",_session.uid]; self.FBUserID = fbUid; [_delegate loggedInFaceBookSuccessfully:fbUid]; } } } 

You will get all the details in json format, which you can see in GDB

+4
source share

All Articles