Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ios-Facebook SDK 3.0 Error 5 When Posting Status Update

I am trying out adding facebook integration in an app using the new (beta) facebook ios sdk 3.0. All I would like to is post a status update to facebook. I used a FBLoginView to login to facebook. I put my app id in the plist as instructed on facebook. I put in some code to post to facebook.

(void)viewDidLoad
{
[super viewDidLoad];
NSArray *perms;
perms = [NSArray arrayWithObjects:@"status_update", nil];
FBLoginView *loginview = 
[[FBLoginView alloc] initWithPermissions:perms];

loginview.frame = CGRectOffset(loginview.frame, 5, 5);
loginview.delegate = self;

[self.view addSubview:loginview];
// Do any additional setup after loading the view, typically from a nib.

}

- (IBAction)poststatus:(UIButton *)sender {
NSString *message = [NSString stringWithFormat:@"Test staus update"];

[FBRequestConnection startForPostStatusUpdate:message
                            completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {

                                [self showAlert:message result:result error:error];

                            }];
}
- (void)showAlert:(NSString *)message
       result:(id)result
        error:(NSError *)error {

NSString *alertMsg;
NSString *alertTitle;
if (error) {
    alertMsg = error.localizedDescription;
    alertTitle = @"Error";
} else {
    NSDictionary *resultDict = (NSDictionary *)result;
    alertMsg = [NSString stringWithFormat:@"Successfully posted '%@'.\nPost ID: %@", 
                message, [resultDict valueForKey:@"id"]];
    alertTitle = @"Success";
}

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:alertTitle
                                                    message:alertMsg
                                                   delegate:nil
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles:nil];
[alertView show];
}

The odd thing is, this code works ONCE. After authenticating the user for the first time, I can post ONE status update successfully. After that, all subsequent attempts will fail with a FBiOSSDK error 5 (in the console, Error: HTTP status code:400). The only way to fix this is to remove the app from the facebook account and re-authenticate. I'm not sure what the problem is. I looked online for solutions but couldn't find anything. If anyone knows how to fix this, please let me know. Thanks

like image 317
benjih555 Avatar asked Aug 07 '12 17:08

benjih555


2 Answers

com.facebook.sdk error 5 is always irritating while working with Facebook iOS sdk. Most of the times it comes with addional in console Error: HTTP status code:400. Its a perception that there is a bug in Facebook iOS sdk that produces this error randomly. I think this error occurs for some certain reasons and sdk do not provide actual reason of error when it occurs.

Several Possible Reasons

  • Every request in sdk is accomplished with completion blocks that we actually pass as argument in completionHandler. This error occurs when a block is in progress and made another request. A simple example might be If you have written request to post on Facebook (startForPostStatusUpdate::) on some button action. On single button tap it would work fine but if you double tap on button it will throw this error com.facebook.sdk error 5

  • If you are trying to post when your current session is not opened. e.g. Once sign in with Facebook then kill the app then reopen and then try to share on Facebook, Result -> com.facebook.sdk error 5. In this case try to reopen session using

  • Facebook do not allow same status to be posted repeatedly, they think it might be some kind of spam e.g. If you are trying to update status and you have hard coded a string lets say @”This is a test status update” you are posing again and again. After 5 to 10 attempts they wont allow you to do anymore. Resulting com.facebook.sdk error 5. If this is the scenario you should change your status string and try updating.

  • Facebook has defined a limit for a particular user to post status using sdk. e.g If you are trying to update status and you have done lets say 15 to 20 status updates. They wont let you do more Resulting -> com.facebook.sdk error 5. In this scenario try to unauthorize the app from your Facebook account and reauthorize it OR try using other Facebook account

like image 128
abdus.me Avatar answered Nov 14 '22 02:11

abdus.me


It seems there might be no answer to the issue. I have checked FB samples coming with SDK, in these examples also the same error happens. So it means after few status updates (15-20) Facebook reaches limits for that particular user. If you log-out for that user and log-in as another user, you can successfully post.

If I will find any extension to limit settings I will reply. Also Facebook doesn't allow for the same Post.

like image 30
Paresh Thakor Avatar answered Nov 14 '22 01:11

Paresh Thakor