I’m using the Facebook Hackbook sample code below in an app. The method getFriendsCallAPIDialogFeed says (in the comments) that this method “get’s the user’s friends, allowing them to pick one and post on their wall”
/*
* Helper method to first get the user's friends then
* pick one friend and post on their wall.
*/
- (void)getFriendsCallAPIDialogFeed {
// Call the friends API first, then set up for targeted Feed Dialog
currentAPICall = kAPIFriendsForDialogFeed;
[self apiGraphFriends];
}
however in line currentAPICall = kAPIFriendsForDialogFeed; it calls the request method below and then kAPIFriendsForDialogFeed.
The problem I’m having is that it picks a user’s friend randomly. I need the user to be able to select a friend of their choice instead.
thanks for any help
- (void)request:(FBRequest *)request didLoad:(id)result {
[self hideActivityIndicator];
if ([result isKindOfClass:[NSArray class]] && ([result count] > 0)) {
result = [result objectAtIndex:0];
}
switch (currentAPICall) {
case kAPIFriendsForDialogFeed:
{
NSArray *resultData = [result objectForKey: @"data"];
// Check that the user has friends
if ([resultData count] > 0) {
// Pick a random friend to post the feed to
int randomNumber = arc4random() % [resultData count];
[self apiDialogFeedFriend:
[[resultData objectAtIndex: randomNumber] objectForKey: @"id"]];
} else {
[self showMessage:@"You do not have any friends to post to."];
}
break;
}
this code populates a table with all friends, from which you can select. the selection only posts a message/request to their notifications and not to their walls – which is what I need.
case kAPIGetAppUsersFriendsUsing:
{
NSMutableArray *friendsWithApp = [[NSMutableArray alloc] initWithCapacity:1];
// Many results
if ([result isKindOfClass:[NSArray class]]) {
[friendsWithApp addObjectsFromArray:result];
} else if ([result isKindOfClass:[NSDecimalNumber class]]) {
[friendsWithApp addObject: [result stringValue]];
}
if ([friendsWithApp count] > 0) {
[self apiDialogRequestsSendToUsers:friendsWithApp];
} else {
[self showMessage:@"None of your friends are using Whatto."];
}
[friendsWithApp release];
break;
}
Use the
resultDatato populate a table and then move the posting code into thedidSelectRowAtIndexPath.This SO question tells you how to post to a friend’s wall: Facebook API: Post on friend wall