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 i
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:
As you are using share dialog, I am going to throw some light on how to post game score using share dialog.
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.
ShareOpenGraphAction action = new ShareOpenGraphAction.Builder() .setActionType("games.achieves") .putObject("game", object) .build();
You can find different ActionTypes
here.
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.
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 theuser_friends
permission.
Hope this will provide you and other users enough information on game integration with Facebook
.
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:-
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 .........
Well, there are 3 things you should do :
1) Categorize your app as Games on Facebook Developers
2) Use the Achievements API and Scores API
3) Facebook for Developers officially has an answer to your question. Please refer to the link https://developers.facebook.com/docs/games/services/scores-achievements
[ OPTIONAL ]
If you want to study about General Sharing from your app by users than this link Facebook SharingAddit might also help you in as General Sharing of content from your app
Just try the below snippet,
call wherever you want like below
ShareDialog shareDialog;
FacebookSdk.sdkInitialize(mContext);
shareDialog = new ShareDialog(mContext);
shareScoreonFB("345"); // just pass your score here in string format. call this inside click listener.
// GLOBAL FUNCTION TO SHARE SCORE ON FB
void shareScoreonFB(String score)
{
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentTitle("Your score is : "+score)
.setContentDescription("Any description that you needed")
.setContentUrl(Uri.parse("https://play.google.com/store/apps/details?id=com.mobtraffiq.numbertap&hl=en")).build();
shareDialog.show(linkContent);
}
NOTE: Make sure you initialize the Facebook SDK.
Hope this helps you, let me know for queries.
You have to use Facebook SDK to do this, I think the main reason is about security.
This is a simple snippet for photo sharing example (not related to your question but i think you know you can't not do it by using Intent):
private void shareImage() {
SharePhoto photo = new SharePhoto.Builder()
.setBitmap(bmp)
.setCaption("Simple puzzle")
.build();
SharePhotoContent content = new SharePhotoContent.Builder()
.addPhoto(photo)
.build();
ShareApi.share(content, null);
}
I believe that the Facebook SDK uses a background Activity for the actual data transfer, but you still need to make your own activity, its layout, and the examples on here show you how to create your own Sharing and Login tools