3

下面的代码尝试在单击 fbloginview 时允许用户的读取权限后重新授权发布权限。

#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];
         }
         ];
    }

它在这里给了我这个错误:

异常'com.facebook.sdk:InvalidOperationException',原因:'FBSession:重新授权无效,而先前的重新授权调用尚未完成。'

是否有可以检测到上一次重新授权调用何时完成的功能?

我尝试使用 openWithPublishPermission 但它不起作用。

4

1 回答 1

5

尝试异步调用它

- (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];
             }];
         };
    }
}
于 2013-03-05T01:26:20.817 回答