Ankit Srivastava
Ankit Srivastava

Reputation: 12405

Post on personal Facebook wall using ios sdk and tag multiple friends at once..?

I am trying to post a message on my wall and wanted to tag multiple users at a time in this post. I tried the various options on the FB post page but couldn't do it. May be I am not doing it right. Any help is appreciated and this is how I am doing it...

NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               @"Test 2",@"message",
                               @"100004311843201,1039844409", @"to",
                               nil];
[self.appDelegate.facebook requestWithGraphPath:@"me/feed" andParams:params andHttpMethod:@"POST" andDelegate:self];

I have also tried message_tags but that doesn't seem to work as well.

Upvotes: 1

Views: 2599

Answers (3)

estemendoza
estemendoza

Reputation: 3085

If you followed the tutorial on how to setup Open Graph for iOS, you can do something like this if you use the friendsPickerController:

// Create an action
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];

//Iterate over selected friends
if ([friendPickerController.selection count] > 0) {
    NSMutableArray *temp = [NSMutableArray new];
    for (id<FBGraphUser> user in self.friendPickerController.selection) {
        NSLog(@"Friend selected: %@", user.name);
        [temp addObject:[NSString stringWithFormat:@"%@", user.id]];
    }
    [action setTags:temp];
}

Basically, you can set an array of friend's ids on the "tags" property on an action

Upvotes: 0

Sohaib Muhammad
Sohaib Muhammad

Reputation: 31

To tag a friend in ur fb status ..you need "facebook id" of your friend by using FBFriendPickerViewController and "place id" using FBPlacePickerViewController. Following code will help you.

NSString *apiPath = nil;

apiPath = @"me/feed";

if(![self.selectedPlaceID isEqualToString:@""]) {

    [params setObject:_selectedPlaceID forKey:@"place"];

}

NSString *tag  = nil;
if(mSelectedFriends != nil){
    for (NSDictionary *user in mSelectedFriends) {
        tag = [[NSString alloc] initWithFormat:@"%@",[user objectForKey:@"id"] ];

        [tags addObject:tag];

    }

    NSString *friendIdsSeparation=[tags componentsJoinedByString:@","];
    NSString *friendIds = [[NSString alloc] initWithFormat:@"[%@]",friendIdsSeparation ];

    [params setObject:friendIds forKey:@"tags"];
}

FBRequest *request = [[[FBRequest alloc] initWithSession:_fbSession graphPath:apiPath parameters:params HTTPMethod:@"POST"] autorelease];

[request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
    [SVProgressHUD dismiss];

    if (error) {
        NSLog(@"Error ===== %@",error.description);
        if (_delegate != nil) {
            [_delegate facebookConnectFail:error requestType:FBRequestTypePostOnWall];
        }else{
            NSLog(@"Error ===== %@",error.description);
        }


    }else{

        if (_delegate != nil) {
            [_delegate faceboookConnectSuccess:self requestType:FBRequestTypePostOnWall];
        }
    }

Upvotes: 2

C Abernathy
C Abernathy

Reputation: 5523

You would need to use Open Graph to tag people with a message. The me/feed Graph API endpoint doesn't support this.

Mentions Tagging https://developers.facebook.com/docs/technical-guides/opengraph/mention-tagging/

Action Tagging: https://developers.facebook.com/docs/technical-guides/opengraph/publish-action/

You can take a look at the Scrumptious sample app that comes included with the latest Facebook SDK for iOS to see how to do this.

Upvotes: 4

Related Questions