Код: Выделить всё
NSArray *permissions = @[@"read_friendlists", @"email",@"user_about_me",@"user_status"];
// OPEN Session!
[FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:YES
completionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
// if login fails for any reason, we alert
if (error) {
//NSLog(@"error %@",error);
// show error to user.
} else if (FB_ISSESSIONOPENWITHSTATE(status)) {
// no error, so we proceed with requesting user details of current facebook session.
//NSLog(@"we are here");
//NSLog(@"----%@",[session accessTokenData].accessToken);
NSString *tok = [session accessTokenData].accessToken;
NSLog(@"tok 2");
[[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary *user, NSError *error) {
if (error) {
NSLog(@"error:%@",error);
}
else
{
NSLog(@"all dat %@",user);
// retrive user's details at here as shown below
NSLog(@"FB user first name:%@",user.first_name);
NSLog(@"FB user last name:%@",user.last_name);
NSLog(@"FB user birthday:%@",user.birthday);
NSLog(@"FB user location:%@",user.location);
NSLog(@"FB user username:%@",user.username);
NSLog(@"FB user gender:%@",[user objectForKey:@"gender"]);
NSLog(@"email id:%@",[user objectForKey:@"email"]);
NSLog(@"location:%@", [NSString stringWithFormat:@"Location: %@\n\n",
user.location[@"name"]]);
}
}];
// [self promptUserWithAccountName]; // a custom method - see below:
}
}];
}
Подробнее здесь: https://stackoverflow.com/questions/235 ... e-username