Search code examples
iosfacebookfacebook-graph-apifacebook-ios-sdk

Facebook Developer API iOS, age_range returns NULL


Here's my code, what am I doing wrong here? Bear in mind that I'm using FBLoginView and the other strings returns actual valid results, just not age range. Thanks in advance, - Daniel

- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView
                        user:(id<FBGraphUser>)user {

NSString *userID = [NSString stringWithFormat:@"%@", user.objectID]; //objectID instead?
NSLog(@"userID = %@", userID);

NSString *nameFull = [NSString stringWithFormat:@"%@", user.name];
NSLog(@"nameFull = %@", nameFull);

NSString *firstName = [NSString stringWithFormat:@"%@", user.first_name];
NSLog(@"firstName = %@", firstName);

NSString *middleName = [NSString stringWithFormat:@"%@", user.middle_name];
NSLog(@"middleName = %@", middleName);

NSString *lastName = [NSString stringWithFormat:@"%@", user.last_name];
NSLog(@"lastName = %@", lastName);

NSString *link = [NSString stringWithFormat:@"%@", user.link];
NSLog(@"link = %@", link);

NSString *gender = [NSString stringWithFormat:@"%@", [user objectForKey:@"gender"]];
NSLog(@"gender = %@", gender);

NSDictionary *ageRangeDict = [user objectForKey:@"user_age_range"];
NSString *ageRange = [NSString stringWithFormat:@"%@-%@",
                      [ageRangeDict objectForKey:@"min"],
                      [ageRangeDict objectForKey:@"max"]];

NSLog(@"ageRange = %@", ageRange);
}

Solution

  • Change this line:

    NSDictionary *ageRangeDict = [user objectForKey:@"user_age_range"];
    

    To this:

    NSDictionary *ageRangeDict = [user objectForKey:@"age_range"];
    

    Reference: Link