How to post to a friend's wall in facebook iOS SDK 3.1?

ⅰ亾dé卋堺 提交于 2019-12-03 21:05:57

I figured it out!

First of course implement FBFriendPickerDelegate per here, unless you already have their friend ID somehow. http://developers.facebook.com/docs/howtos/filter-devices-friend-selector-using-ios-sdk/

Then the important part, how to post to friend's wall:

- (void)facebookViewControllerDoneWasPressed:(id)sender
{
    NSString* fid;
    NSString* fbUserName;

    // get facebook friend's ID from selection. just gets 1 right now.
    for (id<FBGraphUser> user in friendPickerController.selection)
    {
        NSLog(@"\nuser=%@\n", user);
        fid = user.id;

        fbUserName = user.name;
    }

    //Make the post.
    NSMutableDictionary* params = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Join me!", @"message", @"http://itunes.apple.com/my-super-app", @"link", @"My Super App", @"name", nil];

    NSLog(@"\nparams=%@\n", params);

    //Post to friend's wall.
    [FBRequestConnection startWithGraphPath:[NSString stringWithFormat:@"%@/feed", fid] parameters:params HTTPMethod:@"POST"
                          completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
     {
         //Tell the user that it worked.
         UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Shared"
                                                             message:[NSString stringWithFormat:@"Invited %@! error=%@", fbUserName, error]
                                                            delegate:nil
                                                   cancelButtonTitle:@"OK"
                                                   otherButtonTitles:nil];
         [alertView show];
     }
    ];

    //Close the friend picker.
    [self dismissModalViewControllerAnimated:YES];
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!