Facebook iOS:requestNewPublishPermissions不要求用户获得新的权限

时间:2014-08-13 19:21:30

标签: ios facebook

我遇到了requestNewPublishPermissions的问题(我使用的是SDK版本3.17)。 Facebook文档说只用读取权限登录,然后再请求写入权限,这就是我想要做的。我可以让用户使用以下代码登录:

[FBSession openActiveSessionWithReadPermissions:@[@"public_profile"]
                                   allowLoginUI:YES
                              completionHandler:^(FBSession *session, FBSessionState state, NSError *error)
{
     // Handler for session state changes
     // This method will be called EACH time the session state changes,
     // also for intermediate states and NOT just when the session open
     [self sessionStateChanged:session state:state error:error];
}];

然后,当我想发布到时间轴时,我要求使用下面的代码扩展权限。该应用程序通过Facebook网页开始使用Safari。但该网页不是要求写入权限,而是说该应用程序已获得许可。然后当我点击正常,并且控制权返回到应用程序时,我没有发布权限。请参阅“这是最终结果!”下方。

我已尝试访问facebook.com并删除已在“Apps”下提供的权限。这没有任何区别。我还尝试过发布,但这给了我一个错误,说我没有正确的权限。

有什么想法吗?

- (void) requestPublishPermission:(void (^)(void)) action
{
    // Request publish_actions
    [FBSession.activeSession requestNewPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
                                          defaultAudience:FBSessionDefaultAudienceFriends
                                        completionHandler:^(FBSession *session, NSError *error)
     {
         if (!error)
         {
             if ( [FBSession.activeSession.permissions indexOfObject:@"publish_actions"] == NSNotFound )
             {
                 // this is where it ends up!
             }
             else
             {
                 // Permission granted, publish the story
                 action();
             }
         }
         else
         {
             // permission denied, alert user
         }
     }];
}

2 个答案:

答案 0 :(得分:2)

您需要像开发人员/测试人员一样添加您登录的用户。或者您需要将您的应用程序提交到Facebook进行审核。

答案 1 :(得分:0)

我遇到了同样的问题,只有当用户没有使用FB应用程序并且所有内容都通过Web发生时才会发生。这就是我为解决问题所做的工作:

typedef void(^facebookPostCompBlock)(FBSession *session, NSError* err, BOOL publishActionPermissions);

- (void) obtainPostPermissionsWithComplition:(facebookPostCompBlock) comp {
    if ([[FBSession activeSession] isOpen]) {

        if ([[[FBSession activeSession] permissions]indexOfObject:@"publish_actions"] == NSNotFound) {
            [FBSession.activeSession requestNewPublishPermissions:@[@"publish_actions"]
                                                  defaultAudience:FBSessionDefaultAudienceFriends
                                                completionHandler:^(FBSession *session, NSError *error)

             {
                 BOOL gotPublishActionPermissions = TRUE;
                 if ([[[FBSession activeSession] permissions]indexOfObject:@"publish_actions"] == NSNotFound) {
                     gotPublishActionPermissions = FALSE;                     
                 }
                 if (comp) {
                     comp(session,error,gotPublishActionPermissions);
                 }
             }];
        } else {
            if (comp) {
                comp([FBSession activeSession],nil,TRUE);
            }
        }
    } else {
        BOOL openedSynchronously = [FBSession openActiveSessionWithPublishPermissions:@[@"publish_actions"]
                                           defaultAudience:FBSessionDefaultAudienceFriends
                                              allowLoginUI:YES
                                         completionHandler:^(FBSession *session, FBSessionState status, NSError *error)
        {
            if (!error && status == FBSessionStateOpen) {
                [self obtainPostPermissionsWithComplition:comp];
            } else {
                BOOL gotPublishActionPermissions = TRUE;
                if ([[session permissions]indexOfObject:@"publish_actions"] == NSNotFound) {
                    gotPublishActionPermissions = FALSE;
                    BLog(@"+ NOT FOUND +");
                } else {
                   if (comp) {
                       comp(session,error,gotPublishActionPermissions);
                   }
                }
            }
        }];
    }
}

下面唯一关注的问题(需要一个故障安全)是会话将从打开切换到关闭,并且你最终会有一个循环。