Facebook SDK 错误 3 和错误 2

Posted

技术标签:

【中文标题】Facebook SDK 错误 3 和错误 2【英文标题】:Facebook SDK error 3 and error 2 【发布时间】:2013-02-03 00:26:56 【问题描述】:

我有这个应用程序用于在 facebook 上发帖,我目前在某些 ios 6.0 设备上发帖时遇到困难。我只使用 facebook SDK 3.1 并尝试发布操作。以下是我在课堂上用来启动读取权限的代码。

对于访问,我使用以下代码。

// CALLING THIS CODE BLOCK IN ONE BUTTON ACTION.
        if (FBSession.activeSession.isOpen)
        
            [self pickaChoice];
         
        else 
        
            [FBSession openActiveSessionWithPublishPermissions:[NSArray arrayWithObjects:@"publish_actions", nil]
                                               defaultAudience:FBSessionDefaultAudienceEveryone
                                                  allowLoginUI:YES
                                             completionHandler:
             ^(FBSession *session,
               FBSessionState state, NSError *error) 
                 [self sessionStateChanged:session state:state error:error];
             ];
        

- (void)sessionStateChanged:(FBSession *)session
                      state:(FBSessionState) state
                      error:(NSError *)error


    switch (state)
    
        case FBSessionStateOpen:
            [FBSession setActiveSession:session];
            [self pickaChoice];


            break;
        case FBSessionStateClosed:
        case FBSessionStateClosedLoginFailed:
            // Once the user has logged in, we want them to
            // ...

            [FBSession.activeSession closeAndClearTokenInformation];

            break;
        default:
            break;
    

    if (error) 
        NSString* message = [NSString stringWithFormat:@"You have disallowed application to post on your behalf."];
        UIAlertView *alertView = [[UIAlertView alloc]
                                  initWithTitle:@"Error"
                                  message:message
                                  delegate:nil
                                  cancelButtonTitle:@"OK"
                                  otherButtonTitles:nil];
        [alertView show];
        [FBSession.activeSession closeAndClearTokenInformation];
    



-(void)pickaChoice

    /* Just a class to select message and then retrieve the message in the next function 
    -(void)didSelectaPhraseToPost:(NSString *)message   */
    FBPublishViewController *fbPublishViewController = [[FBPublishViewController alloc] initWithNibName:@"FBPublishViewController"
                                                                                                 bundle:[NSBundle mainBundle]];

    fbPublishViewController.selectionDelegate = self;

    [self presentViewController:fbPublishViewController
                       animated:YES
                     completion:^()
                         //nil
                     ];



-(void)didSelectaPhraseToPost:(NSString *)message

    // Selecting a message from a class and retrieving here. This is the message to post on the feed. 

    [self publishMessage:message];


- (void) performPublishAction:(void (^)(void)) action 


    if ([FBSession.activeSession.permissions indexOfObject:@"publish_actions"] == NSNotFound) 
        [FBSession.activeSession reauthorizeWithPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
                                                   defaultAudience:FBSessionDefaultAudienceFriends
                                                 completionHandler:^(FBSession *session, NSError *error) 
                                                     if (!error) 
                                                         action();
                                                     
                                                     //For this example, ignore errors (such as if user cancels).
                                                 ];
     else 
        action();
    



- (void)publishMessage:(NSString *)message

    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   @"APP_NAME", @"name",
                                   message, @"message",
                                   APP_LINK, @"link",
                                   @"APP_PICTURE", @"picture",
                                   nil];

     [self.spinner startAnimating];

       [self performPublishAction:^
            [FBRequestConnection
             startWithGraphpath:@"me/feed"
             parameters:params
             HTTPMethod:@"POST"
             completionHandler:^(FBRequestConnection *connection,
                                 id result,
                                 NSError *error) 


                 [self.spinner stopAnimating];

                 NSString *messageTitle = nil;

                 NSString *message = nil;

                 // If the result came back okay with no errors...
                 if (result && !error)
                 
                     NSLog(@"accessToken : %@",[FBSession activeSession].accessToken );
                     NSLog(@"result : %@",result);
                     messageTitle = @"Success";
                     message = @"App has posted to facebook";

                 else
                     NSLog(@"error : %@",error);
                     messageTitle = @"Error v1.1";
                     //message =  error.localizedDescription;
                     message = @"Unable to process the request. Please check the permissions for the application.";
                     [FBSession.activeSession closeAndClearTokenInformation];
                 

                 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:messageTitle
                                                                 message:message
                                                                delegate:nil
                                                       cancelButtonTitle:@"OK"
                                                       otherButtonTitles: nil];
                 [alert show];

                 //TODO maybe clear connection here if we want to force an new login 

             ];
       ];


现在问题出在某些 iOS 6.0 设备上,它会抛出 facebook.sdk.error 3,而在某些设备上,即使允许应用程序发布,它也会抛出 facebook.sdk.error 2。在当前代码中,我刚刚将消息更改为自定义消息以获得更用户友好的消息,但如果您继续打印本地化描述,它将显示这些消息。

在大多数 iOS 6.0 设备上,代码运行良好,消息已发布。让我知道是否有人可以找出问题的确切位置。我已经在这上面呆了几天,但仍然没有找到问题所在。

编辑 1 我观察到的一种模式是,当安装 facebook 应用程序并且用户通过它登录而不是通过本机设置登录时,我面临着这些困难。

【问题讨论】:

什么样的错误?让我看看你看到的 facebook.sdk.error。 如果设备有 iOS 6 及更高版本,为什么不使用苹果的 facebook 分享视图.. 就像 twitter.. @akiniwa (facebook.sdk.error 3) & 有时 (facebook.sdk.error 2)。 @vishy 你在说 FBNativeDialogs 吗?我试过了。 facebook 上的视图看起来很糟糕。 【参考方案1】:

如果您找到您的 iOS 版本并使用苹果默认的 iOS 6.0 facebook shar 视图会很好,而对于以下版本,您必须使用 Graph API。

【讨论】:

我已经在使用图表路径来发帖,而且它不需要标记朋友或地点等,所以我不必那样塑造它。当我尝试使用不同的 Facebook 帐户时,在同一台设备上它可以工作。您在这里谈论的默认 Facebook 共享视图是什么? FBNativeDialogs??它的自定义选项很少,而且在 facebook 上的视图看起来很糟糕。如果我错过了什么,请告诉我。【参考方案2】:

我在 iOS6 中使用了这种方法,它对我来说很好,可能对你有帮助。

-(void)openFacebookAuthentication

    NSArray *permission = [NSArray arrayWithObjects:kFBEmailPermission,kFBUserPhotosPermission, nil];

    [FBSession setActiveSession: [[FBSession alloc] initWithPermissions:permission] ];

    [[FBSession activeSession] openWithBehavior:FBSessionLoginBehaviorForcingWebView completionHandler:^(FBSession *session, FBSessionState status, NSError *error) 

        switch (status) 
            case FBSessionStateOpen:
                [self getMyData];
                break;
            case FBSessionStateClosedLoginFailed: 
                NSString *errorCode = [[error userInfo] objectForKey:FBErrorLoginFailedOriginalErrorCode];
                NSString *errorReason = [[error userInfo] objectForKey:FBErrorLoginFailedReason];
                BOOL userDidCancel = !errorCode && (!errorReason || [errorReason isEqualToString:FBErrorLoginFailedReasonInlineCancelledValue]);


                if(error.code == 2 && ![errorReason isEqualToString:@"com.facebook.sdk:UserLoginCancelled"]) 
                    UIAlertView *errorMessage = [[UIAlertView alloc] initWithTitle:kFBAlertTitle
                                                                           message:kFBAuthenticationErrorMessage
                                                                           delegate:nil
                                                                           cancelButtonTitle:kOk
                                                                           otherButtonTitles:nil];
                    [errorMessage performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:YES];
                    errorMessage = nil;
                

            
                break;
                // presently extension, log-out and invalidation are being implemented in the Facebook class
            default:
                break; // so we do nothing in response to those state transitions
        
    ];
    permission = nil;

【讨论】:

以上是关于Facebook SDK 错误 3 和错误 2的主要内容,如果未能解决你的问题,请参考以下文章

ios facebook登录sdk 4.28.0错误代码3

iOS 6 facebook sdk 3.1.1 登录错误

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

FB ios SDK 3.13.1 操作无法完成(com.facebook.sdk 错误2)

facebook SDK3.1 和 Xcode 4.5 链接器错误

操作无法完成 com.facebook.sdk 错误 3 - IOS-react-native-FBSDK