在iOS中获取Facebook的个人资料照片

时间:2015-10-09 11:15:37

标签: ios iphone xcode facebook facebook-graph-api

我在我的app&获取用户的详细信息。

我尝试按以下方式获取用户个人资料图片:

 FBimage=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[result valueForKeyPath:@"picture.data.url"]]]];

但这需要将近3分钟才能获得图片和图片。此行以下的代码也将停止执行。

帮我解决这个问题

感谢

3 个答案:

答案 0 :(得分:1)

您可以设置AsyncImageView而不是UIImageview,这样Image就会加载Asyncronouslly

答案 1 :(得分:0)

我对图像也有这种问题。

使用https://github.com/rs/SDWebImage

[imgViewContactImage sd_setImageWithURL:[NSURL URLWithString:@"imagename"]  placeholderImage:[UIImage imageNamed:@"Default"] completed:nil];

导入" UIImageView + WebCache.h"第一

请试一试。

分享您的反馈意见。

快乐的编码。 :)

答案 2 :(得分:0)

    FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
    [login logInWithReadPermissions:@[@"public_profile",@"email",@"picture", @"user_friends"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
        if (error) {
            // Process error

            NSLog(@"efv");
        } else if (result.isCancelled) {
            // Handle cancellations
            NSLog(@"efv");



        } else {
            // If you ask for multiple permissions at once, you
            // should check if specific permissions missing
            if ([result.grantedPermissions containsObject:@"email"]) {
                // Do work
                [self fetchUserDetail];


            }
        }

        [login logOut];

    }];

-(void)fetchUserDetail
{
    if ([FBSDKAccessToken currentAccessToken]) {
        [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name,email,gender,picture"}]
         startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
             if (!error) {


                 NSLog(@"fetched user:%@", result);



             }
             else
             {

             }
         }];
    }
}