如何在facebook iOS SDK 3.1中发布到朋友的墙上?

时间:2012-10-12 00:32:10

标签: facebook-graph-api ios6 facebook-ios-sdk

我有适用于iOS 6的SDK 3.1用于发布状态更新,我有我想要在他们的墙上发布的人的facebook用户ID。

我只想说“嗨”。只到一个人的墙。 我可以用“/ [id] / feed”定位他们的Feed,但是我必须提供图形对象吗?如果我仍然使用startForPostWithGraphPath()。

1 个答案:

答案 0 :(得分:4)

我明白了!

首先当然要在这里实现FBFriendPickerDelegate,除非你已经以某种方式拥有了他们的朋友ID。 http://developers.facebook.com/docs/howtos/filter-devices-friend-selector-using-ios-sdk/

然后重要的部分,如何发布到朋友的墙上:

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