如何仅使用帖子ID与FBWebDialogs分享Facebook帖子?

时间:2013-11-18 03:52:52

标签: ios objective-c facebook-opengraph facebook-ios-sdk

我从FBWebDialogs文档中看到,您可以传递“链接”参数(超链接到外部内容)与Facebook共享。但在我的应用程序中,我没有超链接 - 我只有我希望重新分享的给定facebook帖子的'id'。

问:如果您只有帖子ID,如何分享Facebook帖子?

1 个答案:

答案 0 :(得分:0)

我能够找到适合我的解决方案。基本上你需要构建一个永久链接绑定USER_ID和POST_ID,并将该永久链接作为一个参数传递:

#import "Facebook.h"
    // ...

        // Facebook ID is provided in form {USER_ID}_{POST_ID}
        NSString *rawId = @"113418445354091_460428417431691";

        // Explode the ID into an array with two elements
        NSArray *idArray = [rawId componentsSeparatedByString:@"_"];

        // Build the permalink and bind the USER_ID and _POST_ID
        NSString *path = [NSString stringWithFormat:@"http://www.facebook.com/permalink.php?id=%@&v=wall&story_fbid=%@",[idArray objectAtIndex:0],[idArray objectAtIndex:1]];

        // Build params dict
        NSDictionary *params = @{
                       @"access_token" : @"MY_FACEBOOK_ACCESS_TOKEN",
                       @"name"         : @"My Post Name",
                       @"description"  : @"My Post Description hello there how are you.",
                       @"link"         : path
                       };


        // Call the Dialog
        [FBWebDialogs presentFeedDialogModallyWithSession:nil
                                               parameters:params
                                                  handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error){}
    }];


    // ...
相关问题