【问题标题】:Save Facebook account using ACAccountStore使用 ACAccountStore 保存 Facebook 帐户
【发布时间】:2013-12-05 18:07:50
【问题描述】:

我正在尝试使用 iOS Social.framework 分享到 Facebook。但是,大多数用户不会在 Settings>Facebook 中设置 Facebook,因此当您调出 UIActivityViewController 时,Facebook 不会出现,只是没有列出。 (请参阅UIActivity with no settings for Facebook 或只是谷歌“Facebook 不显示在 UIActivityViewController”,有很多人试图解决这个问题。)

我们的应用程序已经使用了 Facebook SDK,因此我可以获取 Facebook 帐户信息,所以我想我只是获取信息,然后将信息保存在“设置”>“Facebook”中。这是我的代码。 (我从When do we use saveAccount:(ACAccount *)account of ACAccountStore class?iOS requestAccessToAccountsWithType is Not Showing Permission Prompt / NSAlert 得到的)

- (void)storeAccountWithAccessToken:(NSString *)token secret:(NSString *)secret {

    if (self.accountStore == nil) {
        self.accountStore = [[ACAccountStore alloc] init];
    }

    //We start creating an account by creating the credentials object
    ACAccountCredential *credential = [[ACAccountCredential alloc] initWithOAuthToken:token tokenSecret:secret];
    ACAccountType *acctType =[self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
    ACAccount *newAccount = [[ACAccount alloc] initWithAccountType:acctType];
    //Here we assign credentials and now can save account
    newAccount.credential = credential;

    NSDictionary *options = [[NSDictionary alloc] initWithObjectsAndKeys:
                             [VVEnvironment stringForKey:kVVEnvironmentKeyFacebookAppID], (NSString *)ACFacebookAppIdKey,
                             [NSArray arrayWithObject:@"basic_info"], (NSString *)ACFacebookPermissionsKey,
                             ACFacebookAudienceEveryone, (NSString *)ACFacebookAudienceKey,
                             nil];


    [_accountStore requestAccessToAccountsWithType:acctType options:options completion:^(BOOL granted, NSError *error) {
        if (granted == YES) {
            [self.accountStore saveAccount:newAccount withCompletionHandler:^(BOOL success, NSError *error) {

                if (success) {
                    NSLog(@"the account was saved!");
                }
                else {
                    if ([error code] == ACErrorPermissionDenied) {
                        NSLog(@"Got a ACErrorPermissionDenied, the account was not saved!");
                    }
                    NSLog(@"the account was not saved! %d, %@", [error code], error);
                }
            }];
        }
        else {
            NSLog(@"ERR: %@ ",error);
        }
    }];
}

我在那里添加了对 requestAccessToAccountsWithType 的调用,因为没有我从 saveAccount 返回 ACErrorPermissionDenied。当我运行它时,我确实看到我的应用程序在 Facebook 对话框中短暂滑动(如果我在 Facebook 的网站上删除我的应用程序,它确实会显示完整的对话框,询问我授予的权限。)

问题是granted 总是NO,所以我永远没有机会保存帐户。我在这里错过了什么?

我在安装并设置了 Facebook 应用的真实设备上运行它。

如果有任何帮助,我将不胜感激,谢谢!

【问题讨论】:

  • 这个1解决了吗?你能说一下你是如何将令牌和秘密从[FBSession activeSession] accessTokenData.accessToken] Am 中分离出来的吗……
  • 我无法解决这个问题。
  • 只是想知道您是否在 requestAccessTo 之前尝试了 saveAccount...?
  • 是的,来自问题:“我在那里添加了对 requestAccessToAccountsWithType 的调用,因为没有我从 saveAccount 返回 ACErrorPermissionDenied。”
  • 所以它似乎适用于 Twitter(根据您引用的问题)但不适用于 Facebook。非常令人沮丧 - 理想情况下,如果我们只需要注册/登录/共享功能,我们甚至不必使用 FacebookSDK。我希望仅使用社交框架就可以实现。

标签: ios acaccountstore


【解决方案1】:

对此没有可用的解决方案。 iOS 原生 facebook 应用程序不允许写入或保存帐户到ACAccountStore。它只允许从ACAccountStore 访问帐户。 iOS 一次只允许存储 1 个 Facebook 帐户。尝试执行这些步骤你会很容易理解这一点,

  1. 将 facebook 帐户添加到设置应用程序并尝试获得访问权限。它将获得巨大的许可。

  2. 删除帐户并尝试获取将拒绝访问的权限。

  3. 添加一个 facebook 帐户并获得访问权限并尝试将新帐户保存到 ACAccountStore,它会说 Native 应用程序不允许将帐户保存到 ACAccountStore

建议的解决方案是,将帐户添加到设置应用程序并使用它登录并使用社交框架或presentOSIntegratedDialog分享。

【讨论】:

  • 建议的解决方案不是针对应用的解决方案,而是针对用户的行为改变。
  • 只是投反对票,所以它不会得到赏金。我会为你的另一个答案投票,这样你就不会失去声誉点数。
  • @PaulCezanne:你有什么解决方案可以将 Facebook 帐户保存到设置中吗?
  • 不,我没有找到解决方案。
  • 有谁知道这在 OSX 中是否也是不可能的?我得到com.apple.accounts Code=7 "The application is not permitted to access Facebook accounts"。尝试禁用沙盒模式,同样。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-04-24
  • 2011-08-21
  • 1970-01-01
  • 1970-01-01
  • 2013-02-03
  • 2011-06-03
  • 1970-01-01
相关资源
最近更新 更多