拨打电话:
-(void)viewDidLoad)
{
.....
[appDelegate.session openWithCompletionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
self.loginView = [[FBLoginView alloc] initWithReadPermissions:@[@"basic_info", @"email", @"user_birthday", @"user_location"]];
self.loginView.delegate = self;
}];
}
- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView
user:(id<FBGraphUser>)user {
NSLog(@"User firstName From Facebook %@", user.firstName);
NSLog(@"User lastNameFrom Facebook %@", user.lastName);
NSLog(@"User birthday From Facebook %@", user.birthday);
NSLog(@"User country From Facebook %@", user.country);
NSLog(@"User Email From Facebook %@", user.email);
NSLog(@"User location From Facebook %@", user.location);
NSLog(@"User location.location From Facebook %@", user.location.location);
NSLog(@"User location.location.country From Facebook %@", user.location.location.country);
}
日志:
//我得到firstName,lastName,birthday,country和email
对于user.Location:
2014-04-19 16:37:16.143 App[56522:60b] User location From Facebook {
id = 093483980708726711;
name = "San Francisco, California";
}
2014-04-19 16:37:16.143 App[56522:60b] User location.location From Facebook (null)
2014-04-19 16:37:16.143 App[56522:60b] User location.location.country From Facebook (null)
我也试过,但没有用:
[user objectForKey:@"country"]
我做错了什么?我怎样才能回到这个国家?
答案 0 :(得分:2)
试试这个:
NSLog(@"Location name >>> %@", [user objectForKey:@"location"][@"name"]);
NSArray *tempArray = [[user objectForKey:@"location"][@"name"] componentsSeparatedByString:@","];
NSLog(@"City >>> %@", [tempArray objectAtIndex:0]);
NSLog(@"Country >>> %@", [tempArray objectAtIndex:1]);