Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Facebook access token from Social.framework(iOS6)

Tags:

I need to retrieve Facebook access token of my system account, which I set in Settings application.

I know that Social.framework(iOS6) knows all my FB account information & I can perform API calls to Graph API using SLRequest class, like in this post http://blogs.captechconsulting.com/blog/eric-stroh/ios-6-tutorial-integrating-facebook-your-applications

But, my question is - how can I retrieve my Facebook system account's access token?

I found solution for Twitter https://dev.twitter.com/docs/ios/using-reverse-auth , but could you help me with Facebook

like image 859
Rubycon Avatar asked Dec 18 '12 09:12

Rubycon


People also ask

Where is Facebook access token?

Go to https://developers.facebook.com/tools/explorer and replace Graph API Expolrer with the app you've created. Press Get Token and select Get User Access Token. Check the required options on the popup window and choose the permissions needed for your app. Press Get Access Token.

How do you get a long live access token on Facebook?

Using a valid, long-lived access token, your server sends a request to get a code from Facebook. Facebook sends a code back to your server and you securely send this code to the client. The client uses this code to request a long-lived token from Facebook.


1 Answers

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 store self.accountStore = [[ACAccountStore alloc] init];  // Get the Facebook account type for the access request ACAccountType *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");     } }]; 
like image 185
C Abernathy Avatar answered Oct 04 '22 22:10

C Abernathy