Facebook iOS 3.1 sdk login with publish permission callbacks

I'm having trouble logging in with publish permissions in the facebook 3.1 ios sdk.

My app has a button to share a video, and when the user clicks it I want to add the basic + publish permission. As I understand, i have to do two calls -

  1. openActiveSessionWithReadPermissions, and then
  2. reauthorizeWithPublishPermissions

Here's the code I'm using now:

//Opens a Facebook session and optionally shows the login UX.
- (void)openSessionForReadPermissions
{
    [FBSession openActiveSessionWithReadPermissions:nil
                                       allowLoginUI:YES
                                  completionHandler:
     ^(FBSession *session,
       FBSessionState state, NSError *error) {

         //this is called even from the reauthorizeWithPublishPermissions
         if (state == FBSessionStateOpen && !error)
         {
             [self openSessionForPublishPermissions];
         }
         else if (state == FBSessionStateClosedLoginFailed)
         {
             [FBSession.activeSession closeAndClearTokenInformation];

             [[NSNotificationCenter defaultCenter] postNotificationName:FBLoginErrorNotification object:session];
         }
     }];
}

-(void)openSessionForPublishPermissions
{    
    NSArray* permissions = [NSArray arrayWithObject:@"publish_stream"];

    [[FBSession activeSession] reauthorizeWithPublishPermissions:permissions
                                                 defaultAudience:FBSessionDefaultAudienceFriends
                                               completionHandler:
     ^(FBSession *session, NSError *error)
     {
         if (!error)
         {
             [[NSNotificationCenter defaultCenter]
              postNotificationName:FBLoginSuccessNotification
              object:session];
         }
         else
         {
             [[NSNotificationCenter defaultCenter]
              postNotificationName:FBLoginErrorNotification
              object:session];
         }
     }];
}

I see that the block in the openSessionForReadPermissions is called twice (once with FBSessionStateOpen and once with FBSessionStateOpenTokenExtended from the openSessionForPublishPermissions call), and I get a ErrorReauthorizeFailedReasonUserCancelled when first trying to login to the app (if O deleted all app permissions before).

What is the proper way to implement this login? The app does not require Facebook log-in, except for this one feature, so the login process should be on the same button push.

Thanks!

Answers


I ran across this same issue. The solution I found was wrapping the call to [self openSessionForPublishPermissions]; in a dispatch_async block.

Example:

dispatch_async(dispatch_get_current_queue(), ^{
    [self openSessionForPublishPermissions];
});

The reason is that the call to reauthorize.. needs to be after the event loop of which openActiveSession.. is called.


Any chances this could be a timeout for hitting a breakpoint? Got this error once but didn't again after running with breakpoints disabled.


Need Your Help

Django internationalization for admin pages - translate model name and attributes

django internationalization django-admin gettext

Django's internationalization is very nice (gettext based, LocaleMiddleware), but what is the proper way to translate the model name and the attributes for admin pages? I did not find anything abou...

MySQL Error: #1142 - SELECT command denied to user

mysql select command denied

I'm having troubles with a certain query on one of my servers. On all other places I've tested it it works completely fine but on the server i want to use it it isn't working.