ios 操作无法完成。(com.facebook.sdk 错误 2。)ios6

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15831610/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 23:03:03  来源:igfitidea点击:

The operation couldn’t be completed. (com.facebook.sdk error 2.) ios6

iosfacebookios6facebook-login

提问by M S

Hi i am ussing ios6 for facebook login and i am getting this error as native popup

嗨,我正在使用 ios6 登录 Facebook,我收到此错误作为本机弹出窗口

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

操作无法完成。(com.facebook.sdk 错误 2。)

This is the scenario ive used. (I am running this on simularor)

这是我使用的场景。(我在 simularor 上运行这个

I have logged in to the facebook app through settings and i tried to login to my app and its working fine.

我已经通过设置登录到 facebook 应用程序,我尝试登录到我的应用程序并且它工作正常。

Then i logged out of the facebook from settings and logged in again with different user. Then i tried to login to the app. I am getting this error.

然后我从设置中退出了 Facebook 并使用不同的用户再次登录。然后我尝试登录该应用程序。我收到此错误。

I tried loging out of the app using the command

我尝试使用以下命令注销应用程序

[FBSession.activeSession closeAndClearTokenInformation];

[FBSession.activeSession closeAndClearTokenInformation];

But no use.

但是没有用。

The bundle identifier in the facebook app is same as in my ios app.

facebook 应用程序中的包标识符与我的 ios 应用程序中的相同。

this is the code i used to login

这是我用来登录的代码

NSArray *permissions = [[NSArray alloc] initWithObjects:@"email", nil];
    [FBSession openActiveSessionWithReadPermissions:permissions
                                       allowLoginUI:YES
                                  completionHandler:
     ^(FBSession *session,
       FBSessionState state, NSError *error) {
         [self sessionStateChanged:session state:state error:error];
     }];

Any help is appreciated.

任何帮助表示赞赏。

This is the error i am getting

这是我得到的错误

Domain=com.facebook.sdk Code=2 "The operation couldn't be completed. (com.facebook.sdk error 2.)" UserInfo=0x9535330 {com.facebook.sdk:ErrorLoginFailedReason=com.facebook.sdk:SystemLoginDisallowedWithoutError, com.facebook.sdk:ErrorSessionKey=, expirationDate: (null), refreshDate: (null), attemptedRefreshDate: 0001-12-30 00:00:00 +0000, permissions:(null)>}

Domain=com.facebook.sdk Code=2 “操作无法完成。(com.facebook.sdk 错误 2。)” UserInfo=0x9535330 {com.facebook.sdk:ErrorLoginFailedReason=com.facebook.sdk:SystemLoginDisallowedWithoutError, com.facebook.sdk:ErrorSessionKey=, expireDate: (null), refreshDate: (null), 尝试刷新日期: 0001-12-30 00:00:00 +0000, 权限:(null)>}

NOTEI got the same error on a different occation. At that time it was a bug in my code

注意我在不同的场合遇到了同样的错误。当时是我代码中的一个bug

Instead of giving permission as

而不是给予许可

NSArray *permissions = [[NSArray alloc] initWithObjects:@"email",@"birthday", nil];

NSArray *permissions = [[NSArray alloc] initWithObjects:@"email",@"birthday", nil];

i was wrongly doing it as

我做错了

NSArray *permissions = [[NSArray alloc] initWithObjects:@"email,birthday", nil];

NSArray *permissions = [[NSArray alloc] initWithObjects:@"email,birthday", nil];

SOLUTIONEven after correcting the code, I was getting the same error. I have to logout and login the facebook from ios settings screen. Once i did that the correct code never caused any problem. Note that the problem only occured on the device that previously executed the buggy code. Note sure what caused the problem, Hope this info helps someone

解决方案即使在更正代码后,我也遇到了同样的错误。我必须从 ios 设置屏幕注销并登录 Facebook。一旦我这样做了,正确的代码就不会引起任何问题。请注意,该问题仅发生在先前执行错误代码的设备上。请注意导致问题的原因,希望此信息可以帮助某人

回答by Bocaxica

This worked for me:

这对我有用:

  • Go to the settings app of your iPhone.
  • Open your Facebook Settings
  • Scroll down to your app and make sure your app allows facebook interaction.
  • 转到 iPhone 的设置应用程序。
  • 打开您的 Facebook 设置
  • 向下滚动到您的应用并确保您的应用允许 Facebook 互动。

This could happen on any device, therefore in your app you will have to make sure to handle this error correctly. I reckon you give the user feedback why Login With Facebook failed and ask the user to check their Facebook settings on their device.

这可能发生在任何设备上,因此在您的应用程序中,您必须确保正确处理此错误。我认为您向用户提供了为什么 Login With Facebook 失败的反馈,并要求用户检查他们设备上的 Facebook 设置。

 - (void)facebookSessionStateChanged:(FBSession *)session state:(FBSessionState)state error:(NSError *)error
{
    switch (state) {
        case FBSessionStateOpen:
            // handle successful login here
        case FBSessionStateClosed:
        case FBSessionStateClosedLoginFailed:
            [FBSession.activeSession closeAndClearTokenInformation];

            if (error) {
                // handle error here, for example by showing an alert to the user
                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;
    }

回答by Sumit Mundra

check your Bundle identifier for your project and you give Bundle identifier for your app which create on developer.facebook.com that they are same or not.

检查您的项目的捆绑标识符,并为您的应用程序提供捆绑标识符,这些标识符在 developer.facebook.com 上创建,它们是否相同。

回答by nephtes

Another potential cause for this error: Attempting to get permission for a Facebook app in sandbox mode when the Facebook user is not listed in the app's admins, developers or testers.

此错误的另一个潜在原因:当 Facebook 用户未在应用的管理员、开发人员或测试人员中列出时,尝试在沙盒模式下获取 Facebook 应用的权限。

回答by Kirit Vaghela

I solve my problem by passing nil permission while login.

我通过在登录时传递 nil 权限来解决我的问题。

[FBSession openActiveSessionWithReadPermissions:nil
                                       allowLoginUI:YES
                                  completionHandler:

回答by M S

I had a similar issue. the error comes up when the i switched the fb user from setting. Facebook authorization fails on iOS6 when switching FB account on deviceThis solved my problem

我有一个类似的问题。当我从设置中切换 fb 用户时出现错误。在设备上切换 FB 帐户时,Facebook 授权在 iOS6 上失败这解决了我的问题

回答by Sandhya Gade

I had the same issue and took a whole day to figure out the problem. This error message by Facebook SDK is very vague. I had this problem due to openURL: method being overwritten in MyApplication. I removed the overwritten method and facebook login worked fine.

我遇到了同样的问题,花了一整天的时间才找出问题所在。Facebook SDK 的此错误消息非常含糊。由于 openURL: 方法在 MyApplication 中被覆盖,我遇到了这个问题。我删除了覆盖的方法,facebook 登录工作正常。

回答by Josh Liptzin

For me the problem was invalid permissions - I was requesting "birthday" instead of "user_birthday". It's a shame the error message isn't at least minimally descriptive - just saying "permissions invalid" rather than ERROR CODE 2 would have saved me so much time.

对我来说,问题是无效的权限——我请求的是“生日”而不是“user_birthday”。遗憾的是,错误消息至少没有最低限度的描述性 - 只是说“权限无效”而不是错误代码 2 会为我节省很多时间。