带有发布权限回调的 Facebook iOS 3.1 sdk 登录 [英] Facebook iOS 3.1 sdk login with publish permission callbacks

查看:16
本文介绍了带有发布权限回调的 Facebook iOS 3.1 sdk 登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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,然后
  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];
         }
     }];
}

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

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).

实现此登录的正确方法是什么?除了这一功能外,该应用不需要 Facebook 登录,因此登录过程应该在同一按钮按下.

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.

谢谢!

推荐答案

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

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

示例:

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

原因是调用reauthorize..需要在调用openActiveSession..的事件循环之后.

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

这篇关于带有发布权限回调的 Facebook iOS 3.1 sdk 登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆