0

我在应用程序中使用下面的 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;
    }
4

1 回答 1

1

使用resultData填充表格,然后将发布代码移动到didSelectRowAtIndexPath.

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self apiDialogFeedFriend: 
        [[resultData objectAtIndex: indexPath.row] objectForKey: @"id"]];
}

这个 SO 问题告诉您如何在朋友的墙上发帖:Facebook API:在朋友墙上发帖

于 2012-07-24T14:21:58.103 回答