2011-04-07 30 views
4

我有一些代码可以做一堆设置,然后通过FB连接发布到Facebook。在一个点上,我有这样的事情:如何使用iPhone应用程序中的FBConnect在我的提要中包含链接?

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

ALMOST作品!唯一的问题是:在我的描述字符串中,“<a href...”和“</a>”之间的所有内容都不会显示在我的Facebook墙上。

所以问题是:如何添加链接(锚标记样式)作为我的文章的一部分?

+0

有人吗?男人,我 - 一想到这件事真的很容易,一旦学会了“这个窍门”。 – Olie 2011-04-09 15:28:45

回答

14

这是不可能添加链接的描述,但是你可以使用“属性”和“行动”键达到同样的效果,如记录在这里:

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帖子。

Feed Dialog and Facebook post appearance

希望这有助于。

+0

非常感谢!我**只是**发现了属性标记,并且回来输入非常接近完全相同的答案。 :)我要写我的答案没有json作家(只是为了保持低依赖性),但你的是正确的答案。再次感谢! – Olie 2011-04-11 15:30:30

2

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

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


正如预期的那样,这是那些东西,是超简单的,一旦你知道的伎俩之一。

答案是:您不能将HTML放在您的说明字段中。

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

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

,然后将这一对进入PARAMS:

 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]; 
相关问题