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 ……….
@pravin this is error coming after your share API use
@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 …………….
6
Answers
After long searching i found this as work for me in my Project till the actual answer will come ..........
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 .........
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
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):
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.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.In above code snippet key is Object Properties and game.achievement is Object Type. Here is documentation for game:points.
You can find different
ActionTypes
here.show
method onShareDialog
.Summary:-
Note:-
Hope this will provide you and other users enough information on game integration with
Facebook
.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
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
NOTE: Make sure you initialize the Facebook SDK.
Hope this helps you, let me know for queries.