繁体   English   中英

Facebook SDK错误3和错误2

[英]Facebook SDK error 3 and error 2

我有用于在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。 在当前代码中,我刚刚将消息更改为自定义消息,以获取更加用户友好的消息,但是如果继续打印localizedDescription,它将显示这些消息。

在大多数iOS 6.0设备上,代码运行正常,并且消息已发布。 让我知道是否有人可以找到问题所在。 我现在已经花了几天的时间,但仍然没有找到问题所在。

编辑1一种模式,我观察到安装了Facebook应用程序并且用户通过该应用程序登录而不是通过本机设置登录时,我遇到了这类困难。

如果您找到自己的iOS版本,并为iOS 6.0使用Apple的默认Facebook shar视图,那么对于另一版本,则必须使用Graph API。

我使用此方法在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;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM