I'm using the Facebook Android SDK to post a share from my Android app, setting the link to the Google Play url but I want to fill in my own description to be displayed. My description shows up in my preview when I'm posting from my app, but when it gets displayed all that shows is "GET IT ON GOOGLE PLAY" and my description has disappeared.
I am modifying code taken from the Facebook share tutorial included in the SDK (currently using version 3.19.0), here is the ShareDialogBuilder code:
private FacebookDialog.ShareDialogBuilder createShareDialogBuilderForLink() {
return new FacebookDialog.ShareDialogBuilder(this)
.setLink(webLink)
.setName(getString(R.string.fb_name))
.setDescription("Here is my description that I want included in the post.")
.setPicture("http://www.website.com/images/icon.png");
}
I use Facebook SDK 4.0 and this method works fine
if (ShareDialog.canShow(ShareLinkContent.class)) {
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentTitle(getString(R.string.share_onfacebook_title))
.setContentDescription(
getString(R.string.share_onfacebook_message))
.setContentUrl(Uri.parse(getString(R.string.share_onfacebook_url)))
.setImageUrl(Uri.parse(getString(R.string.share_onfacebook_image_url)))
.build();
shareDialog.show(linkContent);
}
Related
I am developing an Android app. In my app, I am integrating Facebook API because I am sharing content from my app to Facebook. I am especially sharing link. So I am using ShareLinkContent option from official Facebook docs. I can successfully share on Facebook. But I am having a problem with this ShareLinkContent option because I cannot set the caption to post that is entered by user.
This is how I share to Facebook:
final ShareLinkContent content = new ShareLinkContent.Builder()
.setContentTitle(shareTitle)
.setImageUrl(Uri.parse(shareImageUrl))
.setContentUrl(Uri.parse(shareContentUrl))
.setContentDescription(shareDescription)
.build();
ShareApi.share(content, null);
I display preview before I share like this:
As you can see now, I can only show preview. But what I want is I want to add an EditText in the preview. The text entered will be shared as post caption on Facebook. But the problem is there is no option setCaption(textUserEntered) in the ShareLinkContent option. I also mentioned options available in the preview image as well.
How can I set post option for ShareLinkContent? That content will be entered by user. How can I get it? Is it possible to use with ShareLinkContent?
I found the solution. Actually I do not need to show custom preview to user. If I build the share content like below code, preview will the option to enter post caption will be automatically added.
final ShareLinkContent content = new ShareLinkContent.Builder()
.setContentTitle(shareTitle)
.setImageUrl(Uri.parse(shareImageUrl))
.setContentUrl(Uri.parse(shareContentUrl))
.setContentDescription(shareDescription)
.build();
ShareDialog shareDialog = new ShareDialog(this);
shareDialog.show(content);
So no need to use
ShareApi.share(content, null);
I am working on an app that I want to be able to post to Facebook wall. The language used for the app is non-latin based character set. Hence, the user types the content to share using the app itself and then share it on facebook without going to the ShareDialog as the content is already typed. I am using Facebook SDK for Android 4.+. Can anyone help me on doing this? All example I got is posting using ShareDialog. Facebook SDK seems to have classes like ShareLinkContent, SharePhoto, ShareMedia but no class to attach simple text content which I am trying to do. Or, can I make the content already typed appear on the ShareDialog's EditText?
Facebook does not allow you to pre-fill the ShareDialog's text. As far as I know there also is no other way to post content on a user's wall.
What is possible is share a link using the ShareDialog, and you can pre-fill the link description and other attributes like image and title but I guess that's not what you want.
An example of that is:
ShareLinkContent content = new ShareLinkContent.Builder()
.setContentDescription(descriptionString)
.setContentUrl(Uri.parse(urlString))
.setImageUrl(Uri.parse(pictureUrlString))
.setContentTitle(titleString)
.build();
ShareDialog dialog = new ShareDialog(this);
dialog.show(content);
private void showFacebookShareDialog() {
if (ShareDialog.canShow(ShareLinkContent.class)) {
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentTitle("Title")
.setContentDescription(
"Share Text")
.setContentUrl(Uri.parse("http://developers.facebook.com/android"))
.build();
shareDialog.show(linkContent);
}
}
I'm wondering if it is possible to change the text that says "SHARE DIALOG EXAMPLE". Where does this text come from? I'm using the latest SDK (4.10)
This is coming from the message you have set up. When you build your ShareLinkContent, add a custom message to say whatever you like. For example,
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentTitle(getString(R.string.facebook_title))
.setContentDescription(R.string.custom_msg)
.setContentUrl(Uri.parse(getActivity().getResources().getString(R.string.social_media_url)))
.build();
shareDialog.show(linkContent);
When I share link with referrer, Facebook SDK (v4.8) will remove it from link.
For example I have following link:
https://play.google.com/store/apps/details?id=com.mypackage.myapp&referrer=utm_source%3Dfacebook
The actual post on wall contains link without referrer:
http://play.google.com/store/apps/details?id=com.mypackage.myapp
Code:
if (ShareDialog.canShow(ShareLinkContent.class)) {
ShareLinkContent content = new ShareLinkContent.Builder()
.setContentUrl(Uri.parse("https://play.google.com/store/apps/details?id=com.mypackage.myapp&referrer=utm_source%3Dfacebook"))
.build();
shareDialog.show(content);
}
I using "ShareDialog" for sharing a link from my app to Facebook wall. When i post a link, it shows the content only in user's timeline and not in home page. What i'm doing wrong?
I'm doing something like that:
// This is how i invokes the shareDialog
FacebookDialog shareDialog = createShareDialogBuilderForLink().build();
private FacebookDialog.ShareDialogBuilder createShareDialogBuilderForLink() {
return new FacebookDialog.ShareDialogBuilder(this)
.setPicture("picture url")
.setName("name")
.setLink("link url");
}
User's timeline:
Home page:
In home page only shows the name of the app which take it from the link i setted(app in google play) without showing the content of the link(descriptiion, name, Caption...).
Its because the user chose to not share the link publicly, do you see the little lock icon alongside the time the link was shared? It shows that link is not shared publicly, if its public the icon changes to globe icon.
What to do now?
1) I don't know whether Facebook API allows to set permissions on the post but you can try, see API documentation.
2) Many users by default set the share permission to private, see whether your account has it private by default by going in Facebook settings.
How about this
ShareDialog shareDialog = new ShareDialog(this);
if (ShareDialog.canShow(ShareLinkContent.class)) {
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentTitle("Title")
.setContentDescription("Description")
.setContentUrl(Uri.parse("Url"))
.build();
shareDialog.show(linkContent);
}