ios - Facebook request for friends returns 0 friends when session is open -
i building ios application connected facebook. got of facebook related code (pretty copied of it) tokencachehowto project. have run 2 problems, 1 had simple fix, think may causing second problem.
at first login wasn't persisting. had copied code tokencachehowto, confused why , looked solution. found question , said if removed @[@"basic_info"]
permissions parameter work. , did. still confused why work. note: removed @[@"basic_info"]
opensessionwithallowloginui
method in app delegate.
my problem want list of users friends, following request in app delegate.
fbrequest* friendsrequest = [fbrequest requestformyfriends]; [friendsrequest startwithcompletionhandler: ^(fbrequestconnection *connection, nsdictionary* result, nserror *error) { nslog(@"under"); nsarray* friends = [result objectforkey:@"data"]; nslog(@"found: %i friends", friends.count); }];
this code outputs found: 0 friends
within app delegate, if put code in same place in tokencachehowto outputs found: x friends
x actual number of friends. confusing me because able users information such id , name facebook , store on server.
i realize there simple solution don't have grasp of facebook sdk yet , i'm stuck.
try working fine me , ensure permissions like
nsarray *array = [nsarray arraywithobjects:@"user_friends", nil];
and fetch friend
-(void)getfriendlist { fbrequest* friendsrequest = [fbrequest requestwithgraphpath:@"me?fields=friends.fields(first_name,last_name)" parameters:nil httpmethod:@"get"]; [friendsrequest startwithcompletionhandler: ^(fbrequestconnection *connection, nsdictionary* result, nserror *error) { nsdictionary* friendsdic = [result objectforkey:@"friends"]; nsarray *friends = [friendsdic objectforkey:@"data"]; (nsdictionary *friend in friends) { nslog(@"firstname %@",friend[@"first_name"]); nslog(@"last name %@",friend[@"last_name"]); } }]; }
Comments
Post a Comment