Pergunta

The code below was trying to reauthorize the publish permission after allowing the user's read permission when the fbloginview was clicked.

#pragma mark FBLoginViewDelegate Method
- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id<FBGraphUser>)user {
    NSLog(@"User info fetched %@ %@", user.name, user.id);

    [Global FBUser:user.first_name lastname:user.last_name fid:user.id];

    if ([[FBSession activeSession] isOpen])
    {
        //[[FBSession activeSession] closeAndClearTokenInformation];

        [[FBSession activeSession] reauthorizeWithPublishPermissions:[[[NSArray alloc] initWithObjects:@"publish_stream", nil] autorelease]
         defaultAudience:FBSessionDefaultAudienceEveryone
         completionHandler:^(FBSession* session, NSError* error)
         {
             if ([delegate respondsToSelector:@selector(SignUpAlertViewWasDone:)])
                 [delegate SignUpAlertViewWasDone:self];

             [self removeFromSuperview];
         }
         ];
    }

It gave me this error here:

exception 'com.facebook.sdk:InvalidOperationException', reason: 'FBSession: It is not valid to reauthorize while a previous reauthorize call has not yet completed.'

Is there a function that I can detect when the previous reauthorized call was completed?

I try using openWithPublishPermission but it doesn't work.

Foi útil?

Solução

try call it asynchronously

- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id<FBGraphUser>)user {

    if ([[FBSession activeSession] isOpen])
    {
        dispatch_async(dispatch_get_current_queue(), ^{
            [[FBSession activeSession] reauthorizeWithPublishPermissions:[[[NSArray alloc] initWithObjects:@"publish_stream", nil] autorelease]
                                                         defaultAudience:FBSessionDefaultAudienceEveryone
                                                       completionHandler:^(FBSession* session, NSError* error)
             {
                 if ([delegate respondsToSelector:@selector(SignUpAlertViewWasDone:)])
                     [delegate SignUpAlertViewWasDone:self];

                 [self removeFromSuperview];
             }];
         };
    }
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top