1

I'm developing an app that post a state on Facebook but I receive this error: the operation couldn’t be completed (com.facebook.sdk error 2) although I have pressed OK when asked if it could publish on Facebook a post. on iPhone settings I have already reset privacy and location, and though I give permission to publish I cannot find my app listed under "privacy" -> "Facebook"

here is my code to get permissions:

-(void)postOnFacebook
{
if (FBSession.activeSession.isOpen)
    [self postOnWall];
else
{
    [FBSession openActiveSessionWithPublishPermissions:[NSArray arrayWithObjects:@"publish_actions", nil]
                                       defaultAudience:FBSessionDefaultAudienceEveryone
                                          allowLoginUI:YES
                                     completionHandler:^(FBSession *session,
                                                         FBSessionState status,
                                                         NSError *error)
     {
         if (error)
         {
             UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                                             message:error.localizedDescription
                                                            delegate:nil
                                                   cancelButtonTitle:@"OK"
                                                   otherButtonTitles:nil];
             [alert show];
         }
         else if (FB_ISSESSIONOPENWITHSTATE(status))
         {
             NSLog(@"Sending post on wall request...");
             [self postOnWall];
         }
     }];
};
}
swifferina
  • 293
  • 4
  • 16

1 Answers1

0

Try this:

Yes, after you see this error, if you go to Settings, you will see that the setting for this app is turned "OFF". But the problem in this case is that the user was never prompted to allow access -- i.e. the setting was turned to OFF automatically on first time access. If the user was asked, then of course that is understandable, but this is not the case (it's as if the SDK silently and automatically pressed Don't Allow for the user). That's why this is a problem.

Before you read any further, I want to note that once the setting is set, you cannot simply repeat the process to test it, because once the setting is set, it will never ask the user (even deleting and reinstalling the app does not help). To test this issue, you need to reset the permissions by going to Settings -> General -> Reset -> Reset Location & Privacy, before you can try to replicate this again.

From testing, I've discovered that if you have offline_access in the permissions you are requesting for the first time, then it will give this login error (and not prompt the user and set the permission to OFF). The SDK does not check and tell you that this permission is not allowed; it just fails to login.

pankaj asudani
  • 862
  • 6
  • 18
  • but the problem is that my app is not even listed under the settings of Facebook ... – swifferina Apr 08 '14 at 09:23
  • I can't see if the switch is ON or OFF because my app is not listed in the settings of facebook for privacy. I already tried the reset and it doesn't work. – swifferina Apr 08 '14 at 09:32
  • Try this link: http://stackoverflow.com/questions/16052078/facebook-registration-the-operation-couldnt-be-completed-com-facebook-sdk-er – pankaj asudani Apr 08 '14 at 09:42
  • Have you solved your problem, if yes, please vote up. – pankaj asudani Apr 08 '14 at 09:52
  • the strange thing is that this error doesn't appear on my iPhone, I'm the administrator of this app. Instead on other 2 iPhone the error appears. The app is not in development mode! – swifferina Apr 08 '14 at 21:02
  • You should note that you have the solution from this post: http://stackoverflow.com/questions/20657780/ios-facebook-sdk-error-domain-com-facebook-sdk-code-2-and-code-7 – Alexander Scholz Aug 28 '15 at 12:41