Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a Facebook access token on iOS

iOS beginner here. I have the following code:

[facebook authorize:nil delegate:self]; NSString *string1=[facebook accessToken]; NSLog(string1); 

The log shows: miFOG1WS_7DL88g6d95Uxmzz7GCShsWx_FHuvZkmW0E.eyJpdiI6IjNZZkFBY1c5ZnBaMGEzOWM2RzNKbEEifQ.LNjl06lsOQCO9ArVARqff3Ur2XQHku3CMHDBKkpGg351EB33LGxVv96Hh5R860KDJL0cLq8QezSW0GovYxnhUucOwxlITV364sVKDXIzC3bAn9P_74r2Axl1SgOaTyMMkQ_aSQ2OWh-8d3Zn9BDt3pXVWzBLJ9I4XAosnw0GjuE

This seems too long to be an access token. I read it's supposed to be only 40 characters long. What am I doing wrong?

like image 296
John Avatar asked May 16 '11 11:05

John


People also ask

How do I get a short live access token on Facebook?

Go to https://developers.facebook.com/tools/explorer/ and select your app from the first drop down menu, in the left. Click on the button "Get access token", and in the "Select Permissions" window, click in "Extended Permissions" and check manage_pages and publish_stream, and click in "Get Access Token" blue button.


1 Answers

Using v3.2.1 as of March 20, 2013 of Facebook SDK.

NSString *fbAccessToken = [[[FBSession activeSession] accessTokenData] accessToken]; 

If you prefer dot syntax,

NSString *fbAccessToken = [FBSession activeSession].accessTokenData.accessToken; 

For those using Swift;

var fbAccessToken = FBSession.activeSession().accessTokenData.accessToken 

Update for v4.1.0 SDK onwards

Objective-C

NSString *fbAccessToken = [FBSDKAccessToken currentAccessToken].tokenString; 

Swift

var fbAccessToken = FBSDKAccessToken.currentAccessToken().tokenString 
like image 112
Nur Iman Izam Avatar answered Sep 23 '22 05:09

Nur Iman Izam