我在app中使用下面的Facebook Hackbook示例代码。方法 getFriendsCallAPIDialogFeed 表示(在评论中)此方法“获取用户的朋友,允许他们选择一个并在他们的墙上发帖”
/*
* 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];
}
然而在 currentAPICall = kAPIFriendsForDialogFeed; 行中,它调用下面的请求方法,然后 kAPIFriendsForDialogFeed 。
我遇到的问题是它会随机选择一位用户的朋友。我需要用户能够选择他们选择的朋友。
感谢您的帮助
- (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;
}
此代码会为所有朋友填充一个表格,您可以从中选择。选择只发布消息/请求到他们的通知而不是他们的墙 - 这是我需要的。
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;
}
答案 0 :(得分:1)
使用resultData
填充表格,然后将发布代码移至didSelectRowAtIndexPath
。
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self apiDialogFeedFriend:
[[resultData objectAtIndex: indexPath.row] objectForKey: @"id"]];
}
这个问题告诉你如何发布到朋友的墙上:Facebook API: Post on friend wall