Reputation: 3622
I want to use the Graph API. And I want to load them into a UITableView. Also loading entire user details is slow... Is there a way that I can make it faster?
One more thing: Is there a way that I can load a page on Facebook in the login window that is provided by the Facebook iOS SDK after the user logs in? Pretty much I want to load a certain fan page with the user's login credentials...
Upvotes: 1
Views: 1632
Reputation: 6717
Using Facebook SDK 3.0 you can get a list of friends this way:
FBRequest* friendsRequest = [FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary* result,
NSError *error) {
NSArray* friends = [result objectForKey:@"data"];
NSLog(@"Found: %i friends", friends.count);
for (NSDictionary<FBGraphUser>* friend in friends) {
NSLog(@"I have a friend named %@ with id %@", friend.name, friend.id);
}
}];
Consider KNMultiItemSelector to manage the pick list for you.
Upvotes: 1
Reputation: 6118
I added the following method to the Facebook Class to get the user's friends list:
-(BOOL) getFriendsList : (id<FBRequestDelegate>) delegate
{
if (! [self isSessionValid])
{
return NO;
}
else
{
[self requestWithGraphPath:@"me/friends" andDelegate:delegate];
return YES;
}
}
For handling the respond from the server i wrote the following method:
- (void)request:(FBRequest *)request didLoad:(id)result
{
NSDictionary * data = result;
NSArray *separatedName;
Contact * current;
_contactsFromFacebook = [[NSMutableDictionary alloc] init];
for (NSDictionary * contact in data)
{
separatedName = [[contact objectForKey:@"name"] componentsSeparatedByString:@" "];
current = [[Contact alloc]
initWithFirstName:[separatedName objectAtIndex:0]
andLastName:[separatedName objectAtIndex:1]];
if(current.alphabeticKey)
{
[self.contactsFromFacebook addObject:current toExsistingArrayWithKey:current.alphabeticKey];
[self addFriendToImportList:current];
}
[current release];
}
self.allKeysSorted = [NSMutableArray arrayWithArray:[self.contactsFromFacebook allKeys]];
[self.tableView reloadData];
}
Notes:
UITableView
[self.tableView reloadData]
to (re)load all the contacts that i just got from facebook. if you will try to call it earlier, like in viewDidLoad
, you will just end up with an empty table because there are no contacts yet.Upvotes: 3