【问题标题】:No prompt when getting Facebook permissions when system FB account is configured配置系统FB账号获取Facebook权限时无提示
【发布时间】:2014-06-18 12:43:25
【问题描述】:

编辑:目前还没有变通办法,但 Facebook 在其自己的 SDK 中似乎已弃用使用系统 FB 登录。我尝试了最新的 SDK,它完全忽略了系统登录。不幸的是,我不能使用最新的 SDK,因为尽管使用了“旧版”设置,但它仍然返回一个不能给我所需的令牌。不过,看看他们如何绕过系统设置可能会很有用!

原Q

我有一个使用 Facebook 进行身份验证的应用程序。

我正在使用 Facebook SDK(3.13.1 - 最后一个 pre api v2 版本)

如果我尝试进行身份验证,只要我没有在系统设置中设置 FB 帐户,一切正常。该应用程序启动 FB 移动应用程序或移动 Safari 以登录并提示我授予必要的权限。

一旦设置了系统帐户,它就会静默失败。我正在两次运行之间删除应用程序,以确保不会持续缺少权限。如果我运行 SDK 附带的一些 FB 示例应用程序,它们会提示许可就好了,所以这显然是我的应用程序或 Facebook 应用程序的配置有问题。

我看过这两个类似的问题:

Facebook Login - If user account is present (and app is not installed) login fails

Facebook Login error when facebook account is already configured in system preferences

但两者都没有提供适合我情况的答案。 (例如,我确实在 Facebook 应用程序中配置了捆绑标识符)

我尝试过使用我自己的自定义登录代码(基于 Facebook 指南)和 FBLoginView,两者效果相同。

我也尝试过使用 ACAccountStore 直接向系统存储发出请求,效果相同。有什么想法吗?

我将包含一些代码,但我相当肯定代码不是问题 - 如果未配置系统 FB 帐户,一切正常:(我在此处更改了我的 FacebookAppIDkey)

ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *facebookType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSDictionary *options = @{  ACFacebookAppIdKey: @"123",
                            ACFacebookPermissionsKey: @[@"public_profile", @"user_likes", @"user_friends", @"email"],
                            ACFacebookAudienceKey: ACFacebookAudienceFriends};

[accountStore requestAccessToAccountsWithType:facebookType options:options completion:^(BOOL granted, NSError *error) {
    if (granted) {
        NSArray *accounts = [accountStore
                accountsWithAccountType:facebookType];
        id facebookAccount = [accounts lastObject];
        DLog(@"%@", facebookAccount);
    }
    else
    {
        if (error)
        {
            DLog(@"%@", error.localizedDescription);
        }
    }
}];

使用 SDK:

[FBSession openActiveSessionWithReadPermissions:@[@"public_profile", @"user_likes", @"user_friends", @"email"]
                                       allowLoginUI:YES
                                  completionHandler:
                                          ^(FBSession *session, FBSessionState state, NSError *error) {

                                              AppDelegate* appDelegate = (AppDelegate *) [UIApplication sharedApplication].delegate;
                                              [appDelegate sessionStateChanged:session state:state error:error];
                                              if ([FBSession activeSession].isOpen) {
                                                  __typeof__(self) strongSelf = weakSelf;
                                                  strongSelf.facebookToken = session.accessTokenData.accessToken;
                                                  [[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error)
                                                  {
                                                      completion(error,(NSDictionary *)result);
                                                  }];
                                              } else {
                                                  completion(error,nil);
                                              }

                                          }];

【问题讨论】:

    标签: ios facebook facebook-ios-sdk acaccountstore


    【解决方案1】:

    问题可能是因为您已经登录但没有访问令牌。 所以你必须检查条件 if(appDelegate.session.state == FBSessionStateCreatedTokenLoaded) .

    希望以下代码对您有所帮助。

    VNSAppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
    
    
    
    
    if (!appDelegate.session.isOpen) {
        // create a fresh session object
        appDelegate.session = [[FBSession alloc] init];
    
        // if we don't have a cached token, a call to open here would cause UX for login to
        // occur; we don't want that to happen unless the user clicks the login button, and so
        // we check here to make sure we have a token before calling open
        if (appDelegate.session.state == FBSessionStateCreatedTokenLoaded) {
            // even though we had a cached token, we need to login to make the session usable
    
            [[appDelegate.session initWithPermissions:appDelegate.permissions]openWithCompletionHandler:^(FBSession *session,
                                                             FBSessionState status,
                                                             NSError *error) {
                // we recurse here, in order to update buttons and labels
                [self updateView];
            }];
    
        }
    

    【讨论】:

    • 我不认为这可以解释为什么内置的 ACAccountStore 东西在根本不使用 FB SDK 时也不起作用......
    • 您使用的是您创建的实际 FacebookAppidkey 还是代码中显示的 @"123"?
    • 如原帖中所述,我已将其更改为:-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-20
    • 2017-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多