Breaking News
Home / iOS / iOS Isuses / FBSession: an attempt was made reauthorize permissions on an unopened session

FBSession: an attempt was made reauthorize permissions on an unopened session

Issue

When an attempt is made to Re-Authorize the Facebook session using the Facebook iOS SDK, the following exception is thrown.

2012-09-30 01:37:46.377 [7894:17c03] *** Terminating app due to uncaught exception ‘com.facebook.sdk:InvalidOperationException’, reason: ‘FBSession: an attempt was made reauthorize permissions on an unopened session’
*** First throw call stack:

Solution

Make sure the FBSession is opened before any attempt is made to authorize or re-authorize any account access permissions.

Example:

// Convenience method to perform some action that requires the “publish_actions” permissions.
– (void) performPublishAction:(void (^)(void)) action {
    // we defer request for permission to post to the moment of post, then we check for the permission   

     // commented out, checking permission and
    // action();
    // return;

    NSArray *perms =FBSession.activeSession.permissions;
   
    if ([perms indexOfObject:@”publish_actions”] == NSNotFound) {
        // if we don’t already have the permission, then we request it now
       
        CCLOG(@”Permission not found ask for”);
        perms = [NSArray arrayWithObject:@”publish_actions”];
       
        FBSession *a = FBSession.activeSession;
        [a reauthorizeWithPublishPermissions:perms                                       defaultAudience:FBSessionDefaultAudienceFriends
                                                 completionHandler:^(FBSession *session, NSError *error) {
                                                     if (!error) {
                                                         action();
                                                     }
                                                     //For this example, ignore errors (such as if user cancels).
                                                 }];
    } else {
        action();
    }
   
}

[pb_builder]

Check Also

Signing Identities, Missing Private Key, Cannot sign App

Issue Cannot sign the App in XCode, says Missing Private Key. <!

Advertisment ad adsense adlogger