I've got some code that does a bunch of set-up, then posts to Facebook using FB-connect. At one 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 is: in my description string, everything between "<a href...
" and "</a>
" doesn't display on my facebook wall.
So the question is: how do I add a link (anchor-tag style) as part of my post?
It is not possible to add links in the description, however you can achieve the same result using the "properties" and "actions" keys, as documented here:
Facebook API Feed Dialog Documentation
The code would be as follows:
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];
The properties will appear in the stream attachment beneath the description, with each property on its own line. The actions will appear next to the "Comment" and "Like" link under posts.
In the attached screenshots you will see how both properties and actions look like. The first screenshot shows how it looks when the dialog pops up on the iPhone. The second screenshot shows the Facebook post with the properties object. The third screenshot shows the Facebook post with both the properties and actions objects.
Hope this helps.
@lancelotavery gave the correct answer, and I accepted it. I had just moments before discovered the properties field and was coming back to enter this answer when I saw his.
I am entering this answer only to demonstrate that the desired behaviour can be done without adding a jsonwriter.
As expected, this was one of those things that's super-easy, once you know the trick.
The answer is: you can't put HTML in your description field.
HOWEVER, the facebook dialog accepts a parameter called "properties", which can be either a string or a string-representation of another dictionary, which can have exactly 2 values, TEXT and HREF. So, adding a line like this one:
NSString* propString = @"{\"Download it free: \":{\"href\":\"http://bit.ly/12345\",\"text\":\"On iTunes AppStore\"}}";
and then inserting this pair into params:
propString, @"properties",
made everything work. So the final edit of my code from 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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With