如何在我的 iPhone 应用程序中通过 fbconnect 获取用户的 Facebook 个人资料图片?

发布于 2024-09-24 14:16:20 字数 254 浏览 2 评论 0原文

可能的重复:
通过 iOS 获取 Facebook 图片时出现问题

如何通过 fbconnect 获取用户的 Facebook 个人资料图片我的应用程序 iPhone?

Possible Duplicate:
Problem getting Facebook pictures via iOS

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

愛上了 2024-10-01 14:16:20

尝试通过 http://developers.facebook.com/docs/api 进行更深入的了解。以下是用户图片的链接:

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

其中 000000000 是登录用户的 ID。

更新,作者:Michael Gaylord
您还可以将类型附加到请求中以获取不同大小的图像。因此,您的请求将类似于: http://graph.facebook.com/00000000/ picture?type=large 用于大图像。其他选项有小型、普通和方形。

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.

聊慰 2024-10-01 14:16:20

我认为最简单的方法是这样的:

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];

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];
瑕疵 2024-10-01 14:16:20

这里使用这些委托方法来获取用户的图片。

当您创建会话时,您将获得名为 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];
}

调用方法 requestWithDelegate 后,如果成功,您将在此方法中获得响应

- (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];
        }

    }
}

您将获得可以在 GDB 中看到的 json 格式的所有详细信息

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文