0

我目前有以下代码,可以选择一个随机的 Facebook 朋友并发布到他们的墙上。我希望能够从所有朋友中进行选择(而不是随机选择一个)并发布到他们的墙上。如果有人可以帮助我使用以下代码,那就太好了:)

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

此代码选择所有朋友,但不会发布到他们的墙上,而是向他们发送通知:

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

2 回答 2

2

在多个用户的墙上发帖违反 Facebook 平台条款。您应该坚持使用 Requests 方法,因为这是向多个用户发送消息的正确方法。

于 2012-07-23T11:36:47.320 回答
1

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

}

于 2012-07-23T11:53:03.137 回答