Facebook iOS 3.1 sdk使用发布权限回调登录

我在使用facebook 3.1 ios sdk中的发布权限登录时遇到问题。

我的应用程序有一个共享video的按钮,当用户点击它时,我想添加基本+发布权限。 据我了解,我必须做两个电话 –

  1. openActiveSessionWithReadPermissions ,然后
  2. reauthorizeWithPublishPermissions

这是我现在使用的代码:

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

我看到openSessionForReadPermissions中的块被调用两次(一次使用FBSessionStateOpen,一次使用来自openSessionForPublishPermissions调用的FBSessionStateOpenTokenExtended),并且在第一次尝试登录应用程序时获得ErrorReauthorizeFailedReasonUserCancelled(如果O之前删除了所有应用程序权限)。

实现此登录的正确方法是什么? 该应用程序不需要Facebook登录,除了这一function,因此登录过程应该在同一个按钮上。

谢谢!

我碰到了同样的问题。 我找到的解决方案是将调用包装到[self openSessionForPublishPermissions]; 在dispatch_async块中。

例:

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

原因是重新授权的调用需要在调用openActiveSession ..的事件循环之后。

这可能是一个超时的命中断点吗? 出现此错误,但在禁用断点运行后没有再次出现此错误。