Share image and link on facebook in android - android

Is there any way to share image and link on facebook in android. I tried below code without success.
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentTitle("Test")
.setContentDescription("Simple Test")
.setContentUrl(Uri.parse("https://material.io/icons/"))
.setImageUrl(Uri.parse("https://data.kaktus.media/file/file/2017-12-08_16-29-44_928522.jpg"))
.build();
AFAIK setImageUrl is now deprecated. The problem is the ImageUrl image is replaced by the ContentUrl image as mentioned in this question FaceBook ShareLinkContent setImageUrl is replaced by ContentUrl metadata in android.

Related

Facebook image sharing with link and title android

my problem is that i am not able to see content title and content description of my sharing image using facebook share in android app.
my code is
if (shareDialog.canShow(ShareLinkContent.class)) {
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentTitle("Content Title")
.setImageUrl(Uri.parse(getIntent().getStringExtra("shareValue")))
.setContentDescription("Content Description")
.build();
shareDialog.show(linkContent); // Show facebook ShareDialog
}
sharing those parameters has been disabled in Facebook graph API
Modeling content

Android issue Text along with image,hashtag sharing using facebook sdk

I need to share image along with the text and pre-populated hash tag to facebook. So i integrate facebook SDK for sharing.For that i used the following code:-
SharePhoto photo = new SharePhoto.Builder()
.setBitmap(image)
.build();
SharePhotoContent content = new SharePhotoContent.Builder()
.addPhoto(photo)
.setShareHashtag(new ShareHashtag.Builder()
.setHashtag("#loveloqal").build())
.build();
Now i can populate the image and hash tag But can't populate the text.i heard that the posting userdefined posts are against the privacy policy of facebook.Is there any way to do this.I searched a lot.Can someone help me to find a solution??
you can use SharelinkContent https://developers.facebook.com/docs/reference/android/current/class/ShareLinkContent/
It is added in facebook-android-sdk:4.6.0
<provider
android:authorities="com.facebook.app.FacebookContentProvider{APP_ID}"
android:name="com.facebook.FacebookContentProvider"
android:exported="true" />
To use it:
Create a provider in your manifest.xml file like above
ShareLinkContent shareLinkContent = new ShareLinkContent.Builder()
.setContentTitle("Your Title")
.setContentDescription("Your Description")
.setContentUrl(Uri.parse("URL[will open website or app]"))
.setImageUrl(Uri.parse("image or logo [if playstore or app store url then no need of this image url]"))
.build();
create Sharelink content with data and image
Show the dialog.
ShareDialog.show(ShowNavigationActivity.this,shareLinkContent);
After some research there is i found that SharelinkContent has bugs in facebook sdk
see this: Description not shown in Facebook ShareDialog
you can use Open Graph instead... see this:
1.https://developers.facebook.com/docs/sharing/opengraph/android
And
How to share Title and description from android to facebook using facebook sdk 4.1.2
Hope it helps u...

How to set post caption in Facebook Share using ShareLinkContent in Android?

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);

setImageUrl in android facebook sdk 4.14.0 is not working when hashTag is included

Here i am trying to share the page with hashtag.
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentTitle("Hello Facebook content tilte")
.setContentDescription("this is content description")
.setContentUrl(Uri.parse("https://www.facebook.com/Fishing-303261736469954/?fref=ts"))
.setImageUrl(Uri.parse("http://www.villathena.com/images/nearby/thumbs/le-bus-bleu-private-tours.jpg")) //Uri.parse("https://d3kvf6cfq06287.cloudfront.net/influencer/image2_1469508676.jpg"))
.setShareHashtag(new ShareHashtag.Builder().setHashtag(influencer.hashtag_name).build())
.build();
shareDialog.show(linkContent);
Problem am facing here is,
-> After posting, I am not getting the image in setImageUrl() in post, instead i am getting the shared page image.
Its for working fine(what i except) without setShareHashTag(),but my requirement is to include the hashtag.
Here i have attached the screenshots,
After posting,
I don't know what is missing,if any one know the answer please help !!
Thanks in advance.

Facebook SDK link share is removing referral url

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);
}

Categories

Resources