Frage

Making the call:

-(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);


}

Log:

//I get the firstName, lastName, birthday, country, and email just fine

For 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)

I also tried, but no avail:

[user objectForKey:@"country"]

What am I doing wrong? How can I get back the Country?

War es hilfreich?

Lösung

Try this:

NSLog(@"Location name >>> %@", [user objectForKey:@"location"][@"name"]);

NSArray *tempArray = [[user objectForKey:@"location"][@"name"] componentsSeparatedByString:@","];

NSLog(@"City >>> %@", [tempArray objectAtIndex:0]);

NSLog(@"Country >>> %@", [tempArray objectAtIndex:1]);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top