Android Facebook API and ShareLinkContent
Solution 1
So, I have found out the reason why my title and description was not visible in facebook.
First of all thanks @mustafasevgi but your solution refers to SDK 3.5.x where I tried to use SDK 4.0
Coming back to the solution...
I have found out that I have set up my content Url to my App inside the Google Play Store. If you set up a content Url outside of Google Play Store the title and description will not be overwritten.
Solution 2
you can use setQuote("Any Description String") method of ShareContent.Builder to set the quote to display for your link. Something like that
if (shareDialog.canShow(ShareLinkContent.class)) {
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setQuote("My new highscore is " + sum.getText() + "!!")
.setContentUrl(Uri.parse("https://play.google.com/store/apps/details?id=de.ginkoboy.flashcards"))
.build();
shareDialog.show(linkContent);
}
P.S. setTitle , setDescription and setImageUrl methods are deprecated now in Latest Facebook SDK
Related videos on Youtube
Oliver Koehler
Updated on September 19, 2022Comments
-
Oliver Koehler over 1 year
for my Android App Game I have implemented a Button that allows the user to share the result of a game.
I have integrated the Facebook SDK, so all classes are known to my project. The manifest contains the following tags:
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id" /> <provider android:authorities="com.facebook.app.FacebookContentProvider16..." android:name="com.facebook.FacebookContentProvider" android:exported="true"/>
When I run the app I can share the result of the game with the code below.
public void onShareResult(View view){ FacebookSdk.sdkInitialize(getApplicationContext()); callbackManager = CallbackManager.Factory.create(); final ShareDialog shareDialog = new ShareDialog(this); shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() { @Override public void onSuccess(Sharer.Result result) { Log.d(LOG_TAG, "success"); } @Override public void onError(FacebookException error) { Log.d(LOG_TAG, "error"); } @Override public void onCancel() { Log.d(LOG_TAG, "cancel"); } }); if (shareDialog.canShow(ShareLinkContent.class)) { ShareLinkContent linkContent = new ShareLinkContent.Builder() .setContentTitle("Game Result Highscore") .setContentDescription("My new highscore is " + sum.getText() + "!!") .setContentUrl(Uri.parse("https://play.google.com/store/apps/details?id=de.ginkoboy.flashcards")) //.setImageUrl(Uri.parse("android.resource://de.ginkoboy.flashcards/" + R.drawable.logo_flashcards_pro)) .setImageUrl(Uri.parse("http://bagpiper-andy.de/bilder/dudelsack%20app.png")) .build(); shareDialog.show(linkContent); } }
However there are some things I do not understand.
- The shared link looks different from what I see in the dialog before I post.
- Images seem to have been available via internet. i.e. It is not possible to set an image of a resource from my project.
Furthermore I have some trouble understanding what Facebook is requiring.
This is how Facebook displays my posting:
And this is how my App seem to post the content
So the question is: Where is my title and description gone???
Best regards
Oliver
-
Oliver Koehler about 9 yearsHave you declared this Activity in your AndroidManifest? Something like
<activity android:name="com.facebook.LoginActivity"...
-
Oliver Koehler about 9 yearsAccording to Reference of LoginActivity you need to declare LoginActivity in your manifest:
<activity android:name="com.facebook.LoginActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:label="@string/app_name" />
-
Satyam over 8 yearsWhat do you mean by "content Url to my App inside the Google Play Store"?
-
Oliver Koehler over 8 years@Satyam: I set the content title, the content description and the content url
ShareLinkContent linkContent = new ShareLinkContent.Builder() .setContentTitle("Game Result Highscore") .setContentDescription("My new highscore is " + sum.getText() + "!!") .setContentUrl(Uri.parse("https://play.google.com/store/apps/details?id=de.ginkoboy.flashcards"))
-
iappmaker over 8 yearsthe above snippet in the reply is same as in the question right ? I do not find any the answer to this issue. Could you please help me
-
iappmaker over 8 yearsCould you please throw some light on " If you set up a content Url outside of Google Play Store"
-
Oliver Koehler over 8 yearsIf you set an URL that targets to "play.google.com/store/apps..." the title and the description will be taken directly from the targeted page. If you set an URL that targets to any url outside of the google play store the title and description, that you have entered in your ShareLinkContent.Builder() is considered. So this can not be solved by changing the code but rather change the URL.