登录Facebook时无法完成操作。(com.facebook.sdk error 2.0) 错误。iOS 6,iPhone3gs



我已经在我的应用程序中集成了facebooksdk 3.2.1,当我试图登录时,我得到了这个错误

The Operation couldn't be completed.(com.facebook.sdk error 2.0) error. iOS 6

这主要发生在用户的手机预装了Facebook应用程序时,当他试图通过我的应用程序登录Facebook时,我会出错。如果我在iPhone中从facebook应用程序注销该帐户,那么它运行良好。

我该如何克服这个问题,请帮我克服这个问题。

作为参考,我使用的代码是

- (void)sessionStateChanged:(FBSession *)session state:(FBSessionState) state error:(NSError *)error
{
    switch (state) {
        case FBSessionStateOpen:
            if (!error) {
                // We have a valid session
                NSLog(@"User session found");
                [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"FBFirstTime"];
                [[NSUserDefaults standardUserDefaults] synchronize];
                [self populateUserDetails];
                if([[NSUserDefaults standardUserDefaults] boolForKey:@"FBFirstTime"])
                {
                  }
                else
                {
                    NSLog(@"1st Time");
                }
            }
            break;
        case FBSessionStateClosed:
        case FBSessionStateClosedLoginFailed:
            [FBSession.activeSession closeAndClearTokenInformation];
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Could not login with Facebook"
                                                            message:@"Facebook login failed. Please check your Facebook settings on your phone."
                                                           delegate:nil
                                                  cancelButtonTitle:@"OK"
                                                  otherButtonTitles:nil];
            [alert show];
            break;
        default:
            break;
    }
    [[NSNotificationCenter defaultCenter] postNotificationName:FBSessionStateChangedNotification object:session];
    if (error) {
        UIAlertView *alertView = [[UIAlertView alloc]
                                  initWithTitle:@"Error"
                                  message:error.localizedDescription
                                  delegate:nil
                                  cancelButtonTitle:@"OK"
                                  otherButtonTitles:nil];
        [alertView show];
    }
}

//

- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
    //    NSArray *permissions = [[NSArray alloc] initWithObjects:@"email", @"user_likes", nil];
    NSArray* permissions = [[NSArray alloc] initWithObjects:@"user_birthday",
                            @"user_about_me",
                            @"user_checkins",
                            @"user_hometown",
                            @"user_activities",
                            @"user_events",
                            nil];
    return [FBSession openActiveSessionWithReadPermissions:permissions
                                              allowLoginUI:allowLoginUI
                                         completionHandler:^(FBSession *session,
                                                             FBSessionState state,
                                                             NSError *error) {
                                             [self sessionStateChanged:session
                                                                 state:state
                                                                 error:error];
                                         }];
}

//

- (void)populateUserDetails
{
    if (FBSession.activeSession.isOpen) {
        [[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
            if (!error) {
                NSThread *contactsObjectsThread = [[NSThread alloc]initWithTarget:self selector:@selector(createUserContactsObjects) object:nil];
                [contactsObjectsThread start];

                [activityView stopAnimating];
            }
        }];
    }
}

检查单点登录关闭developer.facebook.com…

我也遇到过类似的问题,当你更改密码或更改应用程序的fb权限时,fb令牌应该会更改,你需要更新密码或手动再次接受权限。。。

过去,fb-sdk上有一个错误应该修复,所以我的建议是更新到最新版本,检查"子错误",检查问题是否是密码、权限等…并通知用户恢复登录的相关操作

我终于解决了这个问题,https://stackoverflow.com/a/13321162/1079929按照此答案
在我们的developers.facebook中,在我们的应用程序中,我们需要在iOS Native应用程序中添加BundleID,并启用facebook登录。。。修复了问题

确保您在应用程序中使用的捆绑包标识符与创建应用程序时在developer.facebook.com上提供的标识符相同。

相关内容

最新更新