I am getting accessToken through this
NSString * accessToken = [[FBSession activeSession] accessToken];
then user can get user's Facebook data by implementing this method :
- (void)sessionStateChanged:(FBSession *)session state:(FBSessionState) state error:(NSError *)error
{
switch (state)
{ /// **************** IT GIVES THIS ACCESS TOKEN *****************/////////////////////////
case FBSessionStateOpen:
{
// https://graph.facebook.com/me?access_token=%@
accessToken = [[FBSession activeSession] accessToken];
NSLog(@"accessToken: %@",accessToken);
NSString *urlList = [NSString stringWithFormat:@"https://graph.facebook.com/me?access_token=%@",accessToken];
NSURL *url1 = [NSURL URLWithString:urlList];
NSURLRequest *urlReqst = [[NSURLRequest alloc] initWithURL:url1];
NSData *dataConnection = [NSURLConnection sendSynchronousRequest:urlReqst
returningResponse:nil
error:nil];
NSString *jsonData = [[NSString alloc] initWithData:dataConnection
encoding:NSUTF8StringEncoding];
NSDictionary *jsonDic = [jsonData JSONValue];
self.appid = [jsonDic valueForKey:@"id"];
self.appusername = [jsonDic valueForKey:@"username"];
self.appfirst_name = [jsonDic valueForKey:@"first_name"];
self.applast_name = [jsonDic valueForKey:@"last_name"];
self.appname = [jsonDic valueForKey:@"name"];
self.appemailId = [jsonDic valueForKey:@"email"];
[self LoginAPI];
if ([self.navigation.presentedViewController isKindOfClass:[LoginPage class]]) {
[self.navigation.presentedViewController dismissViewControllerAnimated:YES completion:nil];
}
}
break;
case FBSessionStateClosed:
case FBSessionStateClosedLoginFailed:
[self.navigation popToRootViewControllerAnimated:NO];
[self showLoginView];
[self fbDidLogout];
break;
default:
break;
}
if (error)
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
}
And for getting login into app through Facebook login, you may go through this sample
Hope this will help you...