facebookcodenameoneshare-button

Codenameone ShareButton - Sharing URL and Image content to Facebook


I have a Codenameone ShareButton in my app, when pressed opens a dialog containing a list of the standard social media apps, that i have on my device, eg. Facebook, SMS, Email, Twitter.

I am trying to get a combination of text, image and URL into the ShareButton dialog for Facebook, but failing. It seems to work for the other types of media. I have scoured StackOverflow without luck on this one.

I can share an image to facebook successfully:

ShareButton sb = new ShareButton();
sb.setImageToShare(imageFile, "image/png");

I can share a URL to facebook successfully:

ShareButton sb = new ShareButton();
sb.setTextToShare("www.mywebsite.co.uk");

My goal is to share a piece of text, a URL and an image to facebook (which i can do to other media). My issues are:

  1. Text wont display in the facebook app dialog:

    ShareButton sb = new ShareButton();

    sb.setTextToShare("The text i want to display");

I have seen conflicting posts over the years about FB support for this, so maybe i'm doomed on this one. I tried to trick it and prefix or suffix text to the URL but this didn't display that text still.

  1. So I want to display an image and a URL in the post to FB and it really is just one or the other it seems. So the code below will display just the URL on its own in the FB dialog without the image (swapping out the URL for regular text, displays the image and no text):

    ShareButton sb = new ShareButton();

    sb.setImageToShare(imageFile, "image/png");

    sb.setTextToShare("www.mywebsite.co.uk");

I'd be happy with just option 2 if needs be.

To be clear i'm using the facebook app on my device to share and not a token connection direct to facebook. And if it helps i do have my own website, if there was a way to send it content and it dynamically build up the content for display, but that may not be possible (i'm no web developer).


Solution

  • As far as I recall from the last time I was dealing with posting to facebook, they don't allow you to post both an image and text, or a URL and text together. If you want to have something show up in the user's feed that includes both an image and a description, you'll need to create a web page that includes Facebook's supported Open Graph markup, which will cause it to be displayed "nicely" in the user's feed.

    In projects I have worked on in the past, they used dynamic webpages so that it was easy to create a webpage that was specific to the content you want to post in the user's feed. You can essentially generate a separate webpage for each "share" if necessary.

    We used the feed API directly. I'm not sure if it works from the share button, but if you were able to post a URL, then it probably works.