Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Facebook API and ShareLinkContent

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:

This is how Facebook displays my posting:

And this is how my App seem to post the content

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

like image 503
Oliver Koehler Avatar asked Apr 10 '15 05:04

Oliver Koehler


People also ask

What SDK does Facebook use?

Facebook Android SDK enables mobile developers build Facebook apps for Android. It includes features like tracking analytics, data trends, insights on the traffic on your app. User behaviour on how people interact with your app. It also helps track ads engagements, which ads are working which aren't.


2 Answers

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.

like image 130
Oliver Koehler Avatar answered Sep 21 '22 09:09

Oliver Koehler


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

like image 33
Dishant Walia Avatar answered Sep 18 '22 09:09

Dishant Walia