Get Facebook access token from Social.framework(iOS6) Get Facebook access token from Social.framework(iOS6) ios ios

Get Facebook access token from Social.framework(iOS6)


If you already know how to get the account store set up, here's code around it showing how to get the access token:

@property (strong, nonatomic) ACAccountStore *accountStore;@property (strong, nonatomic) ACAccount *fbAccount;...@synthesize accountStore = _accountStore;@synthesize fbAccount = _fbAccount;...// Initialize the account storeself.accountStore = [[ACAccountStore alloc] init];// Get the Facebook account type for the access requestACAccountType *fbAccountType = [self.accountStore    accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];// Request access to the Facebook account with the access info[self.accountStore requestAccessToAccountsWithType:fbAccountType                                           options:fbInfo                                        completion:^(BOOL granted, NSError *error) {    if (granted) {        // If access granted, then get the Facebook account info        NSArray *accounts = [self.accountStore                             accountsWithAccountType:fbAccountType];        self.fbAccount = [accounts lastObject];        // Get the access token, could be used in other scenarios        ACAccountCredential *fbCredential = [self.fbAccount credential];                    NSString *accessToken = [fbCredential oauthToken];        NSLog(@"Facebook Access Token: %@", accessToken);        // Add code here to make an API request using the SLRequest class    } else {        NSLog(@"Access not granted");    }}];