【问题标题】:How to save facebook account to ACAccountStore from facebookSDK如何从 facebookSDK 将 facebook 帐户保存到 ACAccountStore
【发布时间】:2014-01-09 11:34:27
【问题描述】:

我想在 iOS 中将 Facebook 帐户保存到 ACAccountStore

  1. 我会从 facebookSDK 获得accessTocken,但是如何获得令牌和秘密
  2. 如何保存到ACAccountStore

提前致谢。

-------- 编辑--------

我有一个使用 facebook 登录的应用程序,在使用登录信息后需要分享他选择的照片。 我的用例是,

  1. 如果帐户已经在设置应用程序中,那么我可以使用它来登录和分享。

  2. 用户使用 safari 或 webview 登录,然后我可以如何进行共享。

    一个。 facebook SDK 说如果用户需要使用 OS 集成共享控制器,那么,login method used to authenticate the user must be native iOS 6.0 authentication.

    b.如果我需要共享 facebook SDK 使用 facebook App 提供的选项,我不想要这个选项,因为我想尽可能避免 App 切换。

如何解决这个问题..

【问题讨论】:

  • 单独保存访问令牌的动机是什么?
  • 需要将 facebook 账户信息保存到设置应用中,然后我才能使用社交框架与该账户共享...
  • 如果您使用的是 Facebook SDK,它会自动为您保存会话信息。为什么不使用 SDK 提供的 API 进行分享,而不是使用社交框架?
  • 如果我需要与facebook SDK分享,我需要在那边安装facebook App,需要切换应用程序。
  • 我尝试展示 OS 集成对话框,但出现这样的错误。Error Domain=com.facebook.sdk Code=7 "The operation couldn’t be completed. (com.facebook.sdk error 7.)" com.facebook.sdk:DialogReasonKey=com.facebook.sdk:DialogNotSupported

标签: ios facebook acaccount acaccountstore facebook-sdk-3.1


【解决方案1】:

要做到这一点,你应该有一个访问令牌和秘密,

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

//make credentials to assign to ACAccount 
ACAccountCredential *credential = [[ACAccountCredential alloc] initWithOAuthToken:accesstoken tokenSecret:secret];
ACAccountType *acctType =[self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
ACAccount *newAccount = [[ACAccount alloc] initWithAccountType:acctType];

newAccount.credential = credential;

NSDictionary *options = [[NSDictionary alloc] initWithObjectsAndKeys:
                         "xXXXXXX", (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(@"%@",error);
            }
        }];
    }
    else {
        NSLog(@"%@ ",error);
    }
}];

【讨论】:

  • 我将如何获得该秘密和令牌?我有 accessToken。
  • NSString *accessToken = [[FBSession.activeSession accessTokenData] accessToken];
  • 我说我有accessToken但是如何分离token和secret?
  • 在 twitter 和 accessToken 中,我们需要将 token 和 secret 分开。脸书也一样?以及如何?
  • 抱歉在开会。我认为这里不需要秘密。尝试没有它。 @""
猜你喜欢
  • 1970-01-01
  • 2011-06-03
  • 2019-04-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-13
  • 2013-02-03
  • 1970-01-01
相关资源
最近更新 更多