【问题标题】:How to include a link in my feed-post using FBConnect from iPhone app?如何使用 iPhone 应用程序中的 FBConnect 在我的 feed-post 中包含一个链接?
【发布时间】:2011-04-07 00:12:16
【问题描述】:

我有一些代码可以进行大量设置,然后使用 FB-connect 发布到 Facebook。在某一时刻,我有这样的事情:

   NSString *description = 
                           @"Wow, what a great app! "
                           @"Download it free: "
                           @"<a href=\"http://itunes.apple.com/us/app/myApp/id12345?mt=8\">"
                           @"On iTunes AppStore."
                           @"</a>"
                           ;

   // post FB dialog
   NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
//            @"This is what I say about myApp:", @"message",               // user msg
           @"MyApp!", @"name",                                             // Bold/blue name
           @"MyApp is cool!", @"caption",                                   // 1st line
           description, @"description",                                    // 2nd line
           @"http://itunes.apple.com/us/app/myApp/id12345?mt=8", @"link",
           @"http://farm6.static.flickr.com/5230/5576336654_075c2abcf9_s.jpg", @"picture",
           nil];
   [facebook dialog: @"feed"
               andParams: params
               andDelegate: self];

而且它几乎有效!唯一的问题是:在我的描述字符串中,“&lt;a href...”和“&lt;/a&gt;”之间的所有内容都不会显示在我的 Facebook 墙上。

所以问题是:如何在帖子中添加链接(锚标签样式)?

【问题讨论】:

  • 有人吗?伙计,一旦学会了“诀窍”,我就认为这很容易。

标签: iphone ios facebook


【解决方案1】:

无法在描述中添加链接,但是您可以使用“properties”和“actions”键获得相同的结果,如下所述:

Facebook API Feed Dialog Documentation

代码如下:

SBJSON *jsonWriter = [[SBJSON new] autorelease];

NSDictionary *propertyvalue = [NSDictionary dictionaryWithObjectsAndKeys:@"On iTunes AppStore", @"text", @"http://itunes.apple.com/us/app/myApp/id12345?mt=8", @"href", nil];

NSDictionary *properties = [NSDictionary dictionaryWithObjectsAndKeys:propertyvalue, @"Download it free:", nil];

NSDictionary *actions = [NSDictionary dictionaryWithObjectsAndKeys:@"Download it free", @"name",@"http://itunes.apple.com/us/app/myApp/id12345?mt=8", @"link", nil];

NSString *finalproperties = [jsonWriter stringWithObject:properties];

NSString *finalactions = [jsonWriter stringWithObject:actions];

NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               userfbid, @"to",
                               @"http://itunes.apple.com/us/app/myApp/id12345?mt=8", @"link",
                               @"http://farm6.static.flickr.com/5230/5576336654_075c2abcf9_s.jpg", @"picture",
                               @"Name name name", @"name",
                               @"Caption caption caption", @"caption",
                               @"Description description description", @"description",
                               finalproperties, @"properties",
                               finalactions, @"actions",
                               nil];

[_facebook dialog:@"feed" andParams:params andDelegate:self];

属性将出现在描述下方的流附件中,每个属性都在单独的一行中。 这些操作将显示在帖子下的“评论”和“喜欢”链接旁边。

在随附的屏幕截图中,您将看到属性和操作的外观。 第一个屏幕截图显示了对话框在 iPhone 上弹出时的外观。 第二个屏幕截图显示了带有属性对象的 Facebook 帖子。 第三个屏幕截图显示了包含属性和操作对象的 Facebook 帖子。

希望这会有所帮助。

【讨论】:

  • 非常感谢!我刚刚发现了属性标签,然后回来输入几乎完全相同的答案。 :) 我将在没有 json-writer 的情况下编写我的答案(只是为了保持低依赖性),但你的答案是正确的。再次感谢!
【解决方案2】:

@lancelotavery 给出了正确答案,我接受了。我刚刚发现了属性字段,当我看到他的时候回来输入这个答案。

我输入这个答案只是为了证明可以在不添加 jsonwriter 的情况下完成所需的行为。


正如预期的那样,一旦你知道了诀窍,这就是超级简单的事情之一。

答案是:您不能将 HTML 放在描述字段中。

然而,facebook 对话框接受一个名为“properties”的参数,它可以是字符串或另一个字典的字符串表示形式,它可以有两个值,TEXT 和 HREF。所以,添加这样一行:

 NSString* propString = @"{\"Download it free: \":{\"href\":\"http://bit.ly/12345\",\"text\":\"On iTunes AppStore\"}}";

然后将这一对插入到参数中:

       propString, @"properties",

使一切正常。所以我从上面的代码的最终编辑看起来像这样:

   NSString *description = 
                           @"Wow, what a great app! "
                           @"Download it free: "
                           @"<a href=\"http://itunes.apple.com/us/app/myApp/id12345?mt=8\">"
                           @"On iTunes AppStore."
                           @"</a>"
                           ;
   NSString* propString = @"{\"Download it free: \":{\"href\":\"http://bit.ly/12345\",\"text\":\"On iTunes AppStore\"}}";

   // post FB dialog
   NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
//            @"This is what I say about myApp:", @"message",               // user msg
           @"MyApp!", @"name",                                             // Bold/blue name
           @"MyApp is cool!", @"caption",                                   // 1st line
           description, @"description",                                    // 2nd line
           @"http://itunes.apple.com/us/app/myApp/id12345?mt=8", @"link",
           @"http://farm6.static.flickr.com/5230/5576336654_075c2abcf9_s.jpg", @"picture",
           propString, @"properties",
           nil];

   [facebook dialog: @"feed"
               andParams: params
               andDelegate: self];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-08
    • 1970-01-01
    • 2011-02-13
    • 1970-01-01
    • 2021-05-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多