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

放肆的年华 提交于 2020-01-01 07:03:48

问题


I have the SDK 3.1 working for iOS 6 for posting status updates and I have the facebook user id of the person who I want to post on their wall.

I just want it to say "hi." to just one person's wall. I can target their feed with "/[id]/feed" but then I have to supply a graph object? if I use startForPostWithGraphPath() anyways.


回答1:


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


来源:https://stackoverflow.com/questions/12850630/how-to-post-to-a-friends-wall-in-facebook-ios-sdk-3-1

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