hanumanDev
hanumanDev

Reputation: 6614

Selecting and posting to a Facebook Friend's wall from an iOS app

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;
    }

Upvotes: 0

Views: 505

Answers (1)

Dustin
Dustin

Reputation: 6803

Use the resultData to populate a table and then move the posting code into the didSelectRowAtIndexPath.

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

This SO question tells you how to post to a friend's wall: Facebook API: Post on friend wall

Upvotes: 1

Related Questions