Facebook分享帖子,包括网址下的文字

时间:2013-01-04 09:16:28

标签: iphone ios xcode facebook social-networking

这是我想从Facebook上的应用程序获取的帖子,但我无法在网址下添加消息(“这是我的消息”),我能够使用以下网址发布网址和标题代码如下:

Post Should Look like this on Fb

这是我在Fb上发布的无效方法

-(void)fb_share
{
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {

    SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

    SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
        if (result == SLComposeViewControllerResultCancelled) {

            NSLog(@"Cancelled");

        } else

        {
            NSLog(@"Done");
        }

        [controller dismissViewControllerAnimated:YES completion:Nil];
    };
    controller.completionHandler =myBlock;


    [controller setInitialText:@"This is my title"];


    [controller addURL:[NSURL URLWithString:@"http://www.pinterest.com"]];
   // [controller addImage:[UIImage imageNamed:@"fb.png"]];

    [self presentViewController:controller animated:YES completion:Nil];

}
else{
    NSLog(@"UnAvailable");
}

}

这段代码给出了这个结果:

enter image description here

但是我不希望帖子是这样的,我想在网址下给出我自己的消息(比如“这是我的消息”),PLZ任何人都可以告诉我如何以编程方式做到这一点。提前谢谢

1 个答案:

答案 0 :(得分:0)

您的选择是使用iPhone-Facebook-Graph-API这样易于使用。

NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:4];

[variables setObject:@"MESSAGE HERE" forKey:@"message"];
[variables setObject:@"URL HERE" forKey:@"link"];
[variables setObject:@"URL NAME HERE" forKey:@"name"];
[variables setObject:@"URL DESC HERE." forKey:@"description"];

FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:@"me/feed" withPostVars:variables];

编辑:请参阅login-to-facebook-using-fbgraph链接。