以下代码在单击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];
}
];
}
这给了我这个错误:
exception'com.facebook.sdk:InvalidOperationException',原因:'FBSession:在先前的重新授权呼叫尚未完成时重新授权无效。'
当前一次重新授权的呼叫完成时,是否有我可以检测到的功能?
我尝试使用openWithPublishPermission但它不起作用。
答案 0 :(得分: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];
}];
};
}
}