0

I'm working on a game that runs on iOS, Android and Web. On the Web client I can set up a feed dialog that let's a user post on a friend's timeline:

Share on friend-s feed

That's achieved by using this code:

var params =
{
    name: name,
    link: link,
    picture: picture,
    caption: caption,
    description: description,
    actions: actions,
    properties: properties
};

params.method = 'feed';
params.to = friend_id;

FB.ui(params, function(response){
    ...
});

The to field in the params is what makes the dialog select the friend's feed by default.

I want to do the same on the iOS and Android clients, but I can't find a way to achieve this with SDK 4.x.

The docs say:

"With the Share Button you will allow people to share content to their Facebook timeline, to a friend's timeline or in a group."

Although it's true that the dialog allows the player to share on their friend's timeline, there doesn't seem to be a way to select this option before presenting the dialog to the user.

Looking at FBSDKShareDialog's and FBSDKShareLinkContent's interfaces I don't see a way to specify the "to" as we do in JS. Is this functionality just missing from the mobile SDKs?

Mariano Ruggiero
  • 737
  • 4
  • 15

1 Answers1

0

So after some digging in the Facebook SDK's code I found a way to do what I wanted, but it's using undocumented and deprecated code... (according to the code comments this is there to support Unity). So it's not exactly recommended, but just in case it helps someone, here it goes:

On iOS, there's a hidden property in FBSDKShareLinkContent that lets you pass a free-form parameters dictionary for the share dialog in "feed" mode. Normally this is not accessible, but declaring an extension is all that's needed to make it public. Using the "to" key to specify the friend ID makes the dialog work as on the Web.

@interface FBSDKShareLinkContent ()
@property (nonatomic, copy) NSDictionary* feedParameters;
@end

...

FBSDKShareLinkContent* content = [[FBSDKShareLinkContent alloc] init];
content.contentTitle = title;
content.contentDescription = description;
content.contentURL = linkURL;
content.imageURL = imageURL;
content.feedParameters = @{@"to" : friendId}; // Setting hidden property

FBSDKShareDialog* shareDialog = [[FBSDKShareDialog alloc] init];
shareDialog.mode = FBSDKShareDialogModeFeedWeb; // Use feed mode

On Android, there's an undocumented class called ShareFeedContent that can be used instead of the normal ShareLinkContent and contains a toId field which is what I needed.

import com.facebook.share.internal.ShareFeedContent; // Import undocumented class

ShareFeedContent content = new ShareFeedContent.Builder()
    .setLinkName(title)
    .setLinkDescription(description)
    .setLink(linkURL)
    .setPicture(imageURL)
    .setToId(friendId)
    .build(); 

ShareDialog shareDialog = new ShareDialog(activity);
shareDialog.show(content, ShareDialog.Mode.FEED); // Use feed mode

It's probably not a good idea to use these, but they do definitely work. Hopefully someone else has a cleaner alternative.

Mariano Ruggiero
  • 737
  • 4
  • 15