How to get a Facebook access token on iOS
If you are using the Facebook SDK you can use the FBSession
object to get and accessToken.
If the user authenticated to the app and you have an active session use:
NSString * accessToken = [[FBSession activeSession] accessToken];
to get the access token.
It worked for me.
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
You can use delegate method:
- (void)fbDialogLogin:(NSString *)token expirationDate:(NSDate *)expirationDate
for more information you can refer to the following question :Facebook Access Token