Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Share Score on Facebook android

Tags:

I want to share my game score on facebook. I checked lots of links and every post people are saying that POSTING on facebook using INTENT is not possible.If we are using intent than we can share only link.

If we have to share something on facebook than we have to use FaceBook SDK.

I have another doubt that all questions and answers were posted before Year 2014. Is any new thing come after year 2014.

My actual question is that, Is it possible to share score on Facebook using Intent or i have to use Facebook SDK ?

below is the intent code which i used for my application which is not working ......

        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_TEXT, message);
        startActivity(Intent.createChooser(intent, "Share on"));

and below is the FacebookSDK code ...and Problem in this it is not showing score on the Post only link image is showing, and title & description is missing.

  FacebookSdk.sdkInitialize(getApplicationContext());

            shareDialog = new ShareDialog(this);
             if (ShareDialog.canShow(ShareLinkContent.class)) {
                        linkContent = new ShareLinkContent.Builder()
                                .setContentTitle(title)
                                .setContentDescription(description)
                                .setContentUrl(Uri.parse(link)).
                                .setImageUrl(Uri.parse(imageLink)   
                                .build();

                        shareDialog.show(linkContent);
                    }

I used ShareDialog because

The Share dialog switches to the native Facebook for Android app, then returns control to your app after a post is published. If the Facebook app is not installed it will automatically fallback to the web-based dialog.

Below is the output ..........

output

@pravin this is error coming after your share API use

o

@Pravin this is my code of your share answer........

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        FacebookSdk.sdkInitialize(getApplicationContext());
        callbackManager = CallbackManager.Factory.create();

        setContentView(R.layout.activity_facebook);

        Button mShare= (Button) findViewById(R.id.share);

        mShare.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
                        .putString("og:type", "game.achievement")
                        .putString("og:title", "Name of your game")
                        .putString("og:description", "description. You can share your score here")
                        .putString("game:points", "445")
                        .build();

                ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
                        .setActionType("games.achieves")
                        .putObject("game", object)
                        .build();




                if (ShareDialog.canShow(ShareLinkContent.class)) {
                    ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
                            .setPreviewPropertyName("game")
                            .setAction(action)
                            .build();

                    ShareDialog.show(Facebook.this, content);
                }
            }
        });
        shareDialog = new ShareDialog(this);

    }

Thanx in advance ................

like image 446
sushildlh Avatar asked Aug 04 '16 05:08

sushildlh


People also ask

How do I share my game score on Facebook?

By using the Facebook SDK for your supported platforms, you can share links, media and Open Graph stories directly from your game. Sharing via the Share Dialog requires your players to tap an explicit Share button. For games on Facebook, the Share Dialog appears as an overlay on top of your game.

How do I share a Facebook post on Android?

To share a post you see on your Feed: Below a post, tap Share in the bottom right. To share to a friend's timeline, tap Feed below your name, then select On a friend's timeline. Type your friend's name, then tap Share Now.

How do I create a share link on Facebook?

To generate a Facebook Share Button, visit https://developers.facebook.com/docs/plugins/share-button and specify the URL you want people to share as well as the width. Then generate the code, and paste it into your site where you want the button to appear.

How do I share on Facebook?

Things You Should Know. To share a post on your desktop, click “Share” on the post, select a sharing option, add optional text, and click “Post.” For iPhone or Android, tap “Share” on the post, select a sharing option, add optional text, and tap “Post.”


2 Answers

After long searching i found this as work for me in my Project till the actual answer will come ..........

            FacebookSdk.sdkInitialize(getApplicationContext());

            shareDialog = new ShareDialog(this);
            if (ShareDialog.canShow(ShareLinkContent.class)) {
                    linkContent = new ShareLinkContent.Builder()
                        .setQuote("Hi Guys I have completed Game 30 in 19 seconds  in this game")
                        .setImageUrl(Uri.parse("https://lh3.googleusercontent.com/jUej7mN6M6iulmuwmW6Mk28PrzXgl-Ebn-MpTmkmwtOfj5f0hvnuw8j0NEzK0GuKoDE=w300-rw"))
                        .setContentUrl(Uri.parse("https://play.google.com/store/apps/details?id=com.mobtraffiq.numbertap&hl=en"))
                        .build();

                    shareDialog.show(linkContent);
                }

NOTE:-In this code its shared a quota. If any one get other answer please post with output.

Output:-

output

Please post guys if you get the actual answer of this question ....

Thank you for all the user who make their effort .......

I have learn many thing due to your answers .......

enjoy coding .........

like image 159
sushildlh Avatar answered Oct 20 '22 05:10

sushildlh


Scores API

If you just want to share score you can use Scores API(Read Create or Update a Player's Score section). There is very less and unclear information in provided link so below code snippet might work for you.

    Bundle param = new Bundle();
    param.putInt("score", 100);

    new GraphRequest(
    your_access_token,
    "/USER_ID/scores",
    param,
    HttpMethod.POST,
    new GraphRequest.Callback() {
        public void onCompleted(GraphResponse response) {
            /* handle the result */
        }
    }
).executeAsync();

Achievements API

Use Achievements API if you want to publish achievements in your game and reward players with scores for completing those achievements.You have to use Open Graph Stories to publish your game achievements on Facebook. Before publishing stories on behalf of people, You will have to submit them for review. Read this link for more information.There are two ways to publish an Open Graph story:

  1. Using the Share dialog
  2. Using your own custom interface

As you are using share dialog, I am going to throw some light on how to post game score using share dialog.

  1. Create an object with the object type game.achievement and set the properties on that object.
ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
        .putString("og:type", "game.achievement")
        .putString("title", "Title of the achievement type.")
        .putString("og:description", "description. You can share your score here")
        .putInt("game:points", Points in integer)
  .putString("og:url", "url of achievement type") 
  .putString("og:image", "image url") 
  .putString("fb:app_id", "The App ID that owns this achievement type") 
  .build();

In above code snippet key is Object Properties and game.achievement is Object Type. Here is documentation for game:points.

  1. Then create an action and link the object to the action.
ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
    .setActionType("games.achieves")
    .putObject("game", object)
    .build();

You can find different ActionTypes here.

  1. Finally, create the content model to represent the Open Graph story.
ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
    .setPreviewPropertyName("game")
    .setAction(action)
    .build();

All objects and action types in your code must be lowercase. All property names require namespaces.

  1. Present the Share dialog by using the show method on ShareDialog.

ShareDialog.show(activityOrFragment, content);

Summary:-

The Scores API and Achievements API make it easy to build social leaderboards, persist player scores and award achievements to players in a social and cross-platform format. With the Scores API, you can store and reset a player's high-score and pull back a list of their friends' scores to populate a leaderboard. With the Achievements API, you can define a list of custom achievements that players can complete in your game, along with a score value that can be earned with each achievement.

Note:-

Both the Scores API and Achievements API are only available for apps that are categorized as Games.

Because these API let developers write information about player game state to the Graph API, they both require publish_actions permissions, which is subject to Login Review. To retrieve Score and Achievement information about a player's friends, both the player and their friends need to grant the user_friends permission.

Hope this will provide you and other users enough information on game integration with Facebook.

like image 23
Pravin Divraniya Avatar answered Oct 20 '22 03:10

Pravin Divraniya