我通過這個
NSString * accessToken = [[FBSession activeSession] accessToken];
然後用戶可以通過實施該方法獲得用戶的Facebook數據獲得的accessToken:
- (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];
}
}
以及通過Facebook登錄獲取登錄到應用程序,你可能會經歷this sample
希望這會幫助你...
守ld用戶通過fb登錄或其他電子郵件登錄進入應用程序? – bhanu
用戶應通過fb登錄進入.. – iCoder4777
[Facebook訪問令牌服務器端驗證iPhone應用程序]的可能重複(http://stackoverflow.com/questions/5406859/facebook-access-token-server-side-validation- for-iphone-app) – rogerdpack