首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将facebook帐户从ACAccountStore保存到facebookSDK

如何将facebook帐户从ACAccountStore保存到facebookSDK
EN

Stack Overflow用户
提问于 2014-01-09 11:34:27
回答 1查看 1.1K关注 0票数 1

我想把facebook账户保存到ACAccountStore in iOS,

  1. 我会从accessTocken那里得到facebookSDK,但是怎样才能获得秘密
  2. 如何将其保存到ACAccountStore

提前谢谢。

-编辑-编辑

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

  1. 如果帐户已经在设置应用程序,那么我可以使用它登录和分享。
  2. 用户使用safari或webview进行登录,然后我如何继续进行共享。 答: facebook说,如果用户需要使用操作系统集成共享控制器,那么,login method used to authenticate the user must be native iOS 6.0 authentication.。 如果我需要分享由facebook提供的使用facebook应用程序的选项,我不想使用这个选项,因为我希望尽可能避免应用程序切换。

如何解决这个问题..。

EN

回答 1

Stack Overflow用户

发布于 2014-01-09 11:58:31

要做到这一点,你应该有一个秘密,

代码语言:javascript
复制
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);
    }
}];
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21019064

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档