How to include a link in my message using FBConnect from an iPhone application?

I have a code that creates a set of settings, and then posts to Facebook using FB-connect. At some point, I have something like this:

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

And it ALMOST works! The only problem: in my description line everything that is between " <a href... and <a href... " does not appear on my facebook wall.

So the question is: how do I add a link (anchor style) as part of my post?

+4
source share
2 answers

It is not possible to add links to the description, however, you can achieve the same result using the "property" and "action" keys, as described here:

Facebook API Feed API documentation

The code will look like this:

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

Properties will appear in the stream binding under the description, with each property located on a separate line. Actions will appear next to the Comment and How links in the posts.

In the attached screenshots, you will see how both properties and actions look. The first screenshot shows what it looks like when a dialog box appears on the iPhone. The second screen shot shows a Facebook message with the properties object. The third screenshot shows a Facebook message with properties and actions objects.

Feed Dialog and Facebook post appearance

Hope this helps.

+14
source

@lancelotavery gave the correct answer and I accepted it. I just managed to open the properties field and was returning to enter this answer when I saw it.

I enter this answer only to demonstrate that the desired behavior can be done without adding a jsonwriter.


As expected, this was one of those things that were very easy as soon as you know the trick.

Answer: you cannot put HTML in the description field.

HOWEVER, the facebook dialog accepts a parameter called "properties", which can be either a string or a string representation of another dictionary that can have exactly 2 values, TEXT and HREF. So by adding a line like this:

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

and then pasting this pair into the parameters:

  propString, @"properties", 

everything works. So, the final editing of my code above looks something like this:

  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]; 
+2
source

Source: https://habr.com/ru/post/1347007/


All Articles