Reputation: 2783
I am trying to get my friends hometown & location using FB SDK for iOS. But I can not retrieve friends location & hometown. Here is my code
- (IBAction)btnFBLoginTapped:(id)sender {
NSArray *permissions = [[NSArray alloc]initWithObjects:@"email",@"user_birthday",@"user_hometown",@"user_location",@"friends_birthday",@"friends_location",@"friends_hometown", nil];
[FBSession openActiveSessionWithPermissions:permissions allowLoginUI:YES
completionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
// session might now be open.
if (session.isOpen) {
FBRequest *me = [FBRequest requestForMe];
[me startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary<FBGraphUser> *my,
NSError *error) {
NSLog(@"My dcitionary:- %@",my);
NSLog(@"Sessionkey:- %@",session.accessToken);
// Friend request
FBRequest *friendRequest = [FBRequest requestForMyFriends];
[friendRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSDictionary *resultDictionary = (NSDictionary *)result;
NSArray *data = [resultDictionary objectForKey:@"data"];
NSLog(@"Data:- %@",data);
for (NSDictionary *dic in data) {
NSLog(@"ID:- %@",[dic objectForKey:@"id"]);
}
}];
}];
}
}];
}
Also I need to retrieve friends birthday. But I can not retrieve birthday also.
Can someone help with this ?
Upvotes: 2
Views: 4938
Reputation: 1261
data
is an array of FBGraphObject<FBGraphUser>
[friendRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSArray *data = [result objectForKey:@"data"];
for (FBGraphObject<FBGraphUser> * user in data) {
NSLog(@"%@", [user first_name]);
}
...
Upvotes: 3
Reputation: 5523
Check your logic at this point
....
[friendRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSDictionary *resultDictionary = (NSDictionary *)result;
Your result should be an NSArray, not an NSDictionary.
One other thing to double check the results is to put a similar query in the Graph API explorer: https://developers.facebook.com/tools/explorer
You would put me/friends in the Graph API explorer Hint: select the same application you've set up in the Graph API explorer's Application dropdown.
Upvotes: 0