How to get user's facebook profile pic via fbconnect in my app iPhone? [duplicate]
Asked Answered
M

3

7

Possible Duplicate:
Problem getting Facebook pictures via iOS

How to get user's facebook profile pic via fbconnect in my app iPhone?

Marijn answered 24/9, 2010 at 6:42 Comment(1)
easy way: github.com/jonasman/JNSocialDownloadHerren
E
16

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

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

Where 000000000 is an id of user logged.

UPDATE by Michael Gaylord: You can also append the type to the request to get different sized images. So your request will look something like: http://graph.facebook.com/00000000/picture?type=large for a large image. Other options are small, normal and square.

Egyptian answered 24/9, 2010 at 7:1 Comment(1)
You can also append the type to the request to get different sized images. So your request will look something like: graph.facebook.com/00000000/picture?type=large for a large image. Other options are small, normal and square.Debora
R
16

I think the most simple way is this:

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];
Regan answered 23/5, 2011 at 10:33 Comment(0)
S
4

Here use these delegate methods to get the picture of user.

When you create session you will get the 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 method requestWithDelegate you'll get response in this method if succeed

- (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'll get all the details in json format you can see in GDB

Sylas answered 24/9, 2010 at 7:16 Comment(2)
I show user's profile pic in UIWebView but it covers a part of it & i want pic covers whole area of webview. what can i do for resolve it....Marijn
I get solution .........Marijn

© 2022 - 2024 — McMap. All rights reserved.