Facebook登录错误出了问题

时间:2014-06-01 04:03:18

标签: ios facebook facebook-ios-sdk

我正在使用facebook(v3.14.1)IOS sdk并登录我使用下面的代码。

    - (IBAction)loginWithFB:(id)sender {
    if (FBSession.activeSession.state == FBSessionStateOpen
        || FBSession.activeSession.state == FBSessionStateOpenTokenExtended) {
        OOAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
        [appDelegate sessionStateChanged:FBSession.activeSession state:FBSession.activeSession.state error:nil];
    } else {
        [FBSession openActiveSessionWithReadPermissions:@[@"email", @"public_profile", @"user_friends"]
                                           allowLoginUI:YES
                                      completionHandler:
         ^(FBSession *session, FBSessionState state, NSError *error) {
             OOAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
             [appDelegate sessionStateChanged:session state:state error:error];
         }];
    }
}

Code in app delegate function

- (void)sessionStateChanged:(FBSession *)session state:(FBSessionState) state error:(NSError *)error
{
        // If the session was opened successfully
    if (!error && state == FBSessionStateOpen){
        NSLog(@"Session opened");

        [FBRequestConnection startWithGraphPath:@"/me/invitable_friends" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
            NSArray *frnds = result [@"data"];
            NSMutableArray *frinedsIds = [[NSMutableArray alloc] init];
            [frnds enumerateObjectsUsingBlock:^(NSDictionary *obj, NSUInteger idx, BOOL *stop) {
                [frinedsIds addObject:obj[@"id"]];
            }];
            NSDictionary *parameters = error ? nil : @{@"suggestions": [frinedsIds componentsJoinedByString:@","]};
            [FBWebDialogs presentRequestsDialogModallyWithSession:nil
                                                          message:@"Please join with me in test!"
                                                            title:@"Invite a Friend"
                                                       parameters:parameters
                                                          handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
                                                              if (result == FBWebDialogResultDialogCompleted) {
                                                                  NSLog(@"Web dialog complete: %@", resultURL);
                                                                  [self goToRegistration];

                                                              } else {
                                                                  [self goToRegistration];
                                                                  NSLog(@"Web dialog not complete, error: %@", error.description);
                                                              }
                                                          }
                                                      friendCache:nil];
            return;
        }];

    }
    if (state == FBSessionStateClosed || state == FBSessionStateClosedLoginFailed){
            // If the session is closed
        NSLog(@"Session closed");
            // Show the user the logged-out UI
        [UtilityManager showAlertWithMessage:@"You have logged out from facebook login again."];
    }

        // Handle errors
    if (error){
        [UtilityManager showAlertWithMessage:error.debugDescription];
        NSLog(@"Error");
        NSString *alertText;
        NSString *alertTitle;
            // If the error requires people using an app to make an action outside of the app in order to recover
        if ([FBErrorUtility shouldNotifyUserForError:error] == YES){
            alertTitle = @"Something went wrong";
            alertText = [FBErrorUtility userMessageForError:error];
            [UtilityManager showAlertWithMessage:error.debugDescription];
        } else {

                // If the user cancelled login, do nothing
            if ([FBErrorUtility errorCategoryForError:error] == FBErrorCategoryUserCancelled) {
                NSLog(@"User cancelled login");

                    // Handle session closures that happen outside of the app
            } else if ([FBErrorUtility errorCategoryForError:error] == FBErrorCategoryAuthenticationReopenSession){
                alertTitle = @"Session Error";
                alertText = @"Your current session is no longer valid. Please log in again.";
                [UtilityManager showAlertWithMessage:alertText];

                    // For simplicity, here we just show a generic message for all other errors
                    // You can learn how to handle other errors using our guide: https://developers.facebook.com/docs/ios/errors
            } else {
                    //Get more error information from the error
                NSDictionary *errorInformation = [[[error.userInfo objectForKey:@"com.facebook.sdk:ParsedJSONResponseKey"] objectForKey:@"body"] objectForKey:@"error"];

                    // Show the user an error message
                alertTitle = @"Something went wrong";
                alertText = [NSString stringWithFormat:@"Please retry. \n\n If the problem persists contact us and mention this error code: %@", [errorInformation objectForKey:@"message"]];
                [UtilityManager showAlertWithMessage:alertText];
            }
        }
            // Clear this token
        [FBSession.activeSession closeAndClearTokenInformation];
            // Show the user the logged-out UI
    }
}

我有2种类型的fb app配置。当我使用简单类型的fb应用程序和它的应用程序ID然后它正常工作,但当我使用画布和游戏类型的fb应用程序然后在身份验证后,当它来到应用程序时,它显示“抱歉出错了我们正在努力得到这个

任何帮助?

0 个答案:

没有答案
相关问题