Facebook Registration : The operation couldn't be completed (com.facebook.sdk error 2)

后端 未结 6 918
慢半拍i
慢半拍i 2020-12-06 14:04

I am developing an ios phonegap application. For registration i use phonegap facebook plugin. It worked fine for the first time. But now when i try to register it isn\'t wor

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-06 14:55

    If you get warning "Access token is depreciated". Please add or replace your code line by this two lines where you are passing permissions to your app

    [FBSession.activeSession closeAndClearTokenInformation]; 
    
    NSArray *permissions = [NSArray arrayWithObjects:@"email", nil];
    

    If u are doing all the thing right then please check "status" value. If it is 257 then please enable your app in your IPhone facebook settings.

    Here is the code that can help you to understand in better way

       [FBSession openActiveSessionWithReadPermissions:permissions allowLoginUI:YES completionHandler:^(FBSession *session,
                                                                                                         FBSessionState status, NSError *error)
         {
          if (error)
          {
                  NSLog(@"error===%@   status====%u",error,status);
                  // Handle errors
                     [self handleAuthError:error];
             }
             else if (FB_ISSESSIONOPENWITHSTATE(status))
             {
                 [self getData];
             }
         }];
    
    
    -(void)handleAuthError:(NSError *)error{
        NSString *alertMessage, *alertTitle;
    
        if (error.fberrorShouldNotifyUser) {
            // If the SDK has a message for the user, surface it.
            alertTitle = @"Something Went Wrong";
            alertMessage = error.fberrorUserMessage;
        } else if (error.fberrorCategory == FBErrorCategoryUserCancelled) {
            // The user has cancelled a login. You can inspect the error
            // for more context. For this sample, we will simply ignore it.
            NSLog(@"user cancelled login");
        } else {
            // For simplicity, this sample treats other errors blindly.
            alertTitle  = @"Unknown Error";
            alertMessage = @"Error. Please try again later.";
            NSLog(@"Unexpected error:%@", error);
        }
    
        if (alertMessage) {
            [[[UIAlertView alloc] initWithTitle:alertTitle
                                        message:alertMessage
                                       delegate:nil
                              cancelButtonTitle:@"OK"
                              otherButtonTitles:nil] show];
        }
    }
    

    I hope it would work.

提交回复
热议问题