iOS:通过应用程序登录Facebook

时间:2015-05-10 01:30:29

标签: ios facebook

我正在尝试使用FBSDKLoginManager通过我的应用登录Facebook。我在记录时要求一些权限。但每次我收到以下错误:

  

[11624:2243947]数据----(null)   [11624:2243947]访问Facebook页面错误:错误Domain = com.facebook.sdk.core Code = 8“操作无法完成。(com.facebook.sdk.core错误8)”UserInfo = 0x15eb2e80 {com .facebook.sdk:FBSDKErrorDeveloperMessageKey =对不起,此功能现在不可用:处理此请求时出错。请稍后再试.com.facebook.sdk:FBSDKGraphRequestErrorGraphErrorCode = 2,com.facebook.sdk:FBSDKGraphRequestErrorCategoryKey = 0}

有人可以帮忙吗?这是我写的代码:

FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];

[login logInWithPublishPermissions:@[@"publish_actions"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
    NSLog(@"data----%@",result.grantedPermissions);
    if (error) {
        // Process error
        NSLog(@"Access Facebook page error:%@", error);
    } else if (result.isCancelled) {
        // Handle cancellations
    } else {
        // If you ask for multiple permissions at once, you
        // should check if specific permissions missing
        if ([result.grantedPermissions containsObject:@"publish_actions"]) {
            // Do work
            NSLog(@" publish actions permission granted");

            [login logInWithReadPermissions:@[@"user_likes",@"user_birthday"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
                if (error) {
                    // Process error
                } else if (result.isCancelled) {
                    // Handle cancellations
                } else {
                    // If you ask for multiple permissions at once, you
                    // should check if specific permissions missing
                    if ([result.grantedPermissions containsObject:@"user_birthday"]) {
                        // Do work

                        NSLog(@"Permission  2: %@",result.grantedPermissions);
                    }
                }
            }];

        }
    }
}];

1 个答案:

答案 0 :(得分:4)

使用Facebook SDK 4.x登录

将以下代码添加到facebook登录按钮点击:

FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions:@[@"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
 {
     if (error)
     {
         // Error
     }
     else if (result.isCancelled)
     {
         // Cancelled
     }
     else
     {
         if ([result.grantedPermissions containsObject:@"email"])
         {
             [self getFBResult];
         }
     }
}];

获取Facebook结果方法:

-(void)getFBResult
{
    if ([FBSDKAccessToken currentAccessToken])
    {
        [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name, first_name, last_name, picture.type(large), email"}]
         startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
             if (!error)
             {
                 NSLog(@"fb user info : %@",result);
             }
             else
             {
                 NSLog(@"error : %@",error);
             }
         }];   
    }
}

您可以根据需要更改权限字段。