Reputation: 721
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.
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
Upvotes: 12
Views: 15004
Reputation: 711
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
Upvotes: 2
Reputation: 121
I have used WebDialog system but I have this message:
Cannot use SessionLoginBehavior SSO_WITH_FALLBACK when com.facebook.LoginActivity is not declared as an activity in AndroidManifest.xml
does anyone know why?
Upvotes: 0
Reputation: 721
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.
Upvotes: 8
Reputation: 4904
facebook sdk 3.X with use this code.You can use WebDialog.
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import com.facebook.FacebookException;
import com.facebook.FacebookOperationCanceledException;
import com.facebook.Request;
import com.facebook.Response;
import com.facebook.Session;
import com.facebook.SessionState;
import com.facebook.model.GraphUser;
import com.facebook.widget.WebDialog;
import com.facebook.widget.WebDialog.OnCompleteListener;
public class FaceShare extends Activity {
String link = "", id = "", pic = "", title = "";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent i = getIntent();
Bundle b = i.getExtras();
// link = b.getString("link");
// id = b.getString("id");
// pic = b.getString("pic");
// title = b.getString("title");
try {
// start Facebook Login
Session.openActiveSession(this, true, new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
if (session.isOpened()) {
// make request to the /me API
Request.newMeRequest(session, new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user, Response response) {
}
// callback after Graph API response with user object
}).executeAsync();
publishFeedDialog(title, "title", "caption", link, pic);
}
}
// callback when session changes state
});
}
catch (Exception e) {
Log.e("FACE", e.toString());
finish();
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}
private void publishFeedDialog(String name, String caption, String description, String link, String urlPicture) {
Bundle params = new Bundle();
// params.putString("name", name);
// params.putString("caption", caption);
// params.putString("description", description);
// params.putString("link", link);
// params.putString("picture", urlPicture);
params.putString("name", "name");
params.putString("caption", "caption");
params.putString("description", "description");
params.putString("link", "https://s-media-cache-ak0.pinimg.com/236x/1b/2b/19/1b2b19519b1b3439f783181026d9872b.jpg");
params.putString("picture", "https://s-media-cache-ak0.pinimg.com/236x/1b/2b/19/1b2b19519b1b3439f783181026d9872b.jpg");
Session session = Session.getActiveSession();
WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(FaceShare.this, session, params)).setOnCompleteListener(new OnCompleteListener() {
public void onComplete(Bundle values, FacebookException error) {
if (error == null) {
// When the story is posted, echo the success
// and the post Id.
final String postId = values.getString("post_id");
if (postId != null) {
Toast.makeText(getApplicationContext(), "Shared.", Toast.LENGTH_LONG).show();
finish();
}
else {
finish();
}
}
else if (error instanceof FacebookOperationCanceledException) {
finish();
}
else {
Toast.makeText(getApplicationContext(),
"error occured, try again",
Toast.LENGTH_LONG).show();
finish();
}
}
})
.build();
feedDialog.show();
}
}
Upvotes: 0