Hi guys,
Here's an example of Facebook stream customization.
There are three delegate functions you can implement in LF to
customize the FB post. As an example, let's look at customizing the
post for a new fave.
1. Implement the fbWillPostNewFaveForData:withParams: LF delegate
function in your code.
- The first argument is an NSDictionary of values relating to the
object being faved. They are here for convenience, and you can use
them to customize your FB post.
The dictionary keys are:
kLFSocialPostAccountId
kLFSocialPostAccountName
kLFSocialPostLocation
kLFSocialPostObjectName
kLFSocialPostTagId
kLFSocialPostVenueName
kLFSocialPostImage
kLFSocialPostComment
So for example, you can retrieve the name of the object being faved
like so: NSString *objectName = [data
objectForKey:kLFSocialPostObjectName];
2. The second argument is an NSMutableDictonary of the actual Facebook
post. The dictionary keys and expected values are defined here:
http://developers.facebook.com/docs/reference/rest/stream.publish
under the "Parameters" section.
By default, only one key is set, the "attachment key". You have the
option to either modify this key, or add as many more as you would
like.
For example, to simply log what's being sent to FB by default,
implement your delegate function as follows:
- (void)fbWillPostNewFaveForData:(NSDictionary *)data withParams:
(NSMutableDictionary *)params {
// print current (default) Facebook parameters
NSLog(@"Current FB parameters: %@", [params description]);
}
In the log (for the default Cocktails application) you will see
something like this:
attachment = "{\"name\":\"Pale Deacon\", \"description\": \"George
Polak just drank a Pale Deacon.\", \"media\":[{ \"type\": \"image\",
\"src\": \"
http://maps.google.com/maps/api/staticmap?
center=42.385113,-71.077766&zoom=10&size=75x75&maptype=roadmap&markers=color:red|
color:red|42.385113,-71.077766&sensor=false\", \"href\":\"http://
maps.google.com/maps?
f=q&source=s_q&hl=en&geocode=&q=42.385113,-71.077766&sll=42.385113,-71.077766&ie=UTF8&hq=&hnear=42.385113,-71.077766&z=14\"}]}";
This is the payload that is being sent to Facebook and specifies the
post content. If you want to change what the post body looks like,
modify the value for this ("attachment") key as you like.
To add more FB parameters, simply add them to the dictionary. For
example, if we want to add action links to our FB post, according to
Facebook's documentation we use the "action_links" key. So our
implementation will look like this:
- (void)fbWillPostNewFaveForData:(NSDictionary *)data withParams:
(NSMutableDictionary *)params {
// add an "action link" to the Facebook post
NSString *actionLinks = @"[{\"text\":\"Skyhook\", \"href\":
\"
http://skyhookwireless.com\"}]";
[params setObject:actionLinks forKey:@"action_links"];
}
This adds a text link called Skyhook pointing to Skyhook's website to
the footer of Facebook's post. Note that the original "attachment" key
is still there, we are simply appending to the default post.