简体   繁体   中英

Posting to Facebook friends wall instead of sending a notification with iOS

I currently have the following code that chooses a random Facebook friend and posts to their wall. I would like to be able to choose from all friends (not select a random one) and post to their wall. If anyone could help me with the following code that would be great :)

 case gkAPIFriendsForDialogFeed:
            {
                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 selects all friends but doesn't post to their wall instead it sends them a notification:

case gkAPIGetAppUsersFriendsUsing:
        {
            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;
        }

Posting to multiple users' walls is against Facebook Platforms Terms. You should stick with the Requests method instead, as that is the correct way to message multiple users.

Call this function after get random id.

and change parameter according to your app.

-(void)sendFBPost:(UIButton *)tag

{

NSString *Message = [NSString stringWithFormat:@"-posted via iPhone App"];
NSMutableDictionary *params1 = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                Message, @"message", nil];
NSString *post=[[appDelegate.FBFriendListArray objectAtIndex:tag.tag] objectForKey:@"id"];

[[appDelegate facebook] requestWithGraphPath:[NSString stringWithFormat:@"/%@/feed",post] andParams:params1 andHttpMethod:@"POST" andDelegate:self];

UIAlertView  *alert = [[UIAlertView alloc] initWithTitle:@"Message!" message:@"Invitation Send Sucessfully" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
[alert release];

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM