在我的应用程序中使用facebook登录时,始终返回错误FBErrorCategoryUserCancelled [英] Always return Error FBErrorCategoryUserCancelled while login with facebook in my application

查看:680
本文介绍了在我的应用程序中使用facebook登录时,始终返回错误FBErrorCategoryUserCancelled的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,有三种登录方式。其中一个是用facebook登录。但是,当我点击Facebook按钮时,它要求我访问权限,当点击确定然后它返回错误 FBErrorCategoryUserCancelled 。并且这不会发生在每个设备上,它发生在某些设备上。这是我的代码 -

In my Application there are three ways of login. one of them is login with facebook. But when I click on facebook button it ask me for accesing permissions, when click OK then it returs error FBErrorCategoryUserCancelled. And this is not happening on every devices, it happens on some devices. Here is my code -

if ([[FBSession activeSession]isOpen]) {
    /*
     * if the current session has no publish permission we need to reauthorize
     */
    if ([[[FBSession activeSession]permissions]indexOfObject:@"publish_actions"] == NSNotFound) {

        [[FBSession activeSession] requestNewPublishPermissions:[NSArray arrayWithObject:@"publish_actions"] defaultAudience:FBSessionDefaultAudienceFriends
                                              completionHandler:^(FBSession *session,NSError *error){

                                                  [ProgressHUD dismiss];
                                                  self.view.userInteractionEnabled = YES;

                                              }];

    }else{

        [self fetchUserDetails];
    }

}else{
    /*
     * open a new session with publish permission
     */
    [FBSession openActiveSessionWithPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
                                       defaultAudience:FBSessionDefaultAudienceOnlyMe
                                          allowLoginUI:YES
                                     completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
                                         if (!error && status == FBSessionStateOpen) {

                                             [self fetchUserDetails];

                                         }else{

                                             NSLog(@"error");

                                             if ([FBErrorUtility shouldNotifyUserForError:error]) {
                                                 alertTitle = @"Facebook Error";
                                                 alertMessage = [FBErrorUtility userMessageForError:error];

                                                 // This code will handle session closures that happen outside of the app
                                                 // You can take a look at our error handling guide to know more about it
                                                 // https://developers.facebook.com/docs/ios/errors
                                             } else if ([FBErrorUtility errorCategoryForError:error] == FBErrorCategoryAuthenticationReopenSession) {
                                                 alertTitle = @"Session Error";
                                                 alertMessage = @"Your current session is no longer valid. Please log in again.";

                                                 // If the user has cancelled a login, we will do nothing.
                                                 // You can also choose to show the user a message if cancelling login will result in
                                                 // the user not being able to complete a task they had initiated in your app
                                                 // (like accessing FB-stored information or posting to Facebook)

                                             } else if ([FBErrorUtility errorCategoryForError:error] == FBErrorCategoryUserCancelled) {
                                                 NSLog(@"user cancelled login");

                                                 alertTitle  = @"Facebook Error";
                                                 alertMessage = @"System login cancelled";

                                                 // For simplicity, this sample handles other errors with a generic message
                                                 // You can checkout our error handling guide for more detailed information
                                                 // https://developers.facebook.com/docs/ios/errors
                                             } else {
                                                 alertTitle  = @"Something went wrong";
                                                 alertMessage = @"Please try again later.";
                                                 NSLog(@"Unexpected error:%@", error);
                                             }

                                                 [[[UIAlertView alloc] initWithTitle:alertTitle
                                                                             message:alertMessage
                                                                            delegate:nil
                                                                   cancelButtonTitle:@"OK"
                                                                   otherButtonTitles:nil] show];

                                             [ProgressHUD dismiss];
                                             self.view.userInteractionEnabled = YES;

                                         }
                                     }];
}

任何帮助都将不胜感激。谢谢。

Any help will be appreciated.Thank you.

推荐答案

在我的情况下,这是因为facebook应用程序的沙盒模式仍然打开,因此导致FBErrorCategoryUserCancelled为任何非管理员/开发人员/测试人员该应用程序。

In my case it was because the facebook app's sandbox mode was still on, and therefore result in FBErrorCategoryUserCancelled for anyone who is not an administrator/developer/tester of the app.

要在Facebook上关闭沙盒模式,请转到
https://developers.facebook.com/apps/YOUR_FACEBOOK_APP_ID/review-status/

To turn off sandbox mode on facebook, go to https://developers.facebook.com/apps/YOUR_FACEBOOK_APP_ID/review-status/

查看其中的位置你想让这个应用程序及其所有实时功能向公众开放吗?,使它成为YES。 (您可能需要先插入联系电子邮件才能访问此选项)。

See where it says "Do you want to make this app and all its live features available to the general public?", make it to be YES. (You might need to insert a contact email before you can access this option).

或者,如果您不想让应用程序公开,请邀请测试人员成为应用程序的管理员/开发人员/测试人员。此人需要先接受您的邀请才能使用。

Or, if you don't want to make the app go public just yet, invite the tester to be an admin/developer/tester of the app. The person need to accept your invitation before he can use it.

这篇关于在我的应用程序中使用facebook登录时,始终返回错误FBErrorCategoryUserCancelled的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆