1

I want to save the facebook account to ACAccountStore in iOS,

  1. I will get accessTocken from facebookSDK but how to obtain tocken and secret
  2. How to save it to ACAccountStore

Thanks in Advance.

------ Edit--------

I have an application that uses facebook to login and after with login information need to share photos that he selected. My use cases are,

  1. If account already in settings app then I can use it for login and share.

  2. User using safari or webview for login then how I can proceed for sharing.

    a. facebook SDK says If the user need to use OS integrated share controller then, login method used to authenticate the user must be native iOS 6.0 authentication..

    b. If I need to share option that provided by facebook SDK uses facebook App I don't want this option because I want to avoid App switching as much as possible.

How to solve this..

Rafeek
  • 523
  • 3
  • 16
  • What's the motivation for saving the access token separately? – Ming Li Jan 10 '14 at 18:06
  • Need to save the facebook account information to settings App then only I can use social framework to share with that account... – Rafeek Jan 13 '14 at 06:32
  • If you're using the Facebook SDK, it automatically saves the Session information for you. Why not use the APIs provided by the SDK to share rather than using the social framework? – Ming Li Jan 13 '14 at 17:30
  • If I need to share with facebook SDK I need to install the facebook App over there, app switching is required. – Rafeek Jan 15 '14 at 05:51
  • and I tried to present OS integrated Dialog and I got error like this.. `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` – Rafeek Jan 15 '14 at 06:43
  • I need more context on what you're trying to do in order to help. Code would be very helpful. There are multiple different types of dialogs you can use in order to share (with FB app installed or not), you can also get publish permissions directly, and share without any facebook dialogs. – Ming Li Jan 15 '14 at 18:06
  • I edited with more details. and method that I used for presenting OSIntegratedShareDialog is, `+ (BOOL)presentOSIntegratedShareDialogModallyFrom:(UIViewController*)viewController session:(FBSession*)session initialText:(NSString*)initialText images:(NSArray*)images urls:(NSArray*)urls handler:(FBOSIntegratedShareDialogHandler)handler;` – Rafeek Jan 16 '14 at 05:56
  • If you want to use the iOS integrated share sheet, then you have to get the login credentials from iOS, there's no way to work around it. – Ming Li Jan 16 '14 at 22:25
  • Yea then facebook SDK is not useful, If I have only login and sharing. – Rafeek Jan 21 '14 at 07:08
  • Well, a significant amount of users do not have iOS integration turned on, so if you ONLY use iOS integrated sharing/login, then you're ignoring a lot of potential users. – Ming Li Jan 21 '14 at 21:34
  • k. So you are saying its better to avoid login with social networks?.. Actualy login with social networks will helps to avoid form filling right? – Rafeek Jan 22 '14 at 05:24
  • No, I'm saying you should use the Facebook SDK for iOS, which handles login via iOS, the Facebook app, or web dialog, and also offers different types of share dialogs (and you can do checks on which one to show based on what's available). – Ming Li Jan 22 '14 at 18:15
  • k. If I use facebook SDK and facebook App is not installed on that device then I need to force the user to do what Social framework provide right there is no difference in that right?. If they allow to share through safari or webview that will be great.. – Rafeek Jan 23 '14 at 04:04
  • You do not need to force Social framework, if the FB app is not installed, the SDK will fall back to using the Webview for login. There is also a Webview share dialog (under FBWebDialogs) that you can use. – Ming Li Jan 23 '14 at 23:33
  • which method? can you specify it? – Rafeek Jan 24 '14 at 05:16

1 Answers1

0

to do it you should have an accesstoken and secret,

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);
    }
}];
Zeeshan
  • 4,194
  • 28
  • 32