I'm working with Facebook sdk 4.0 on my android app and I found this problem:
-when I share a post, I can see the facebook interface and I can post it and cancel it perfectly. I registered the callbacks, but if I press the cancel button, the onCancel callback is not called, the post is not published, but the onSuccess callback is called. However, if I touch the close button, everything works ok.
Here is my code:
private void fbOnShare(){
ShareLinkContent shareContent = new ShareLinkContent.Builder()
.setContentTitle("The Simpson!")
.setContentUrl(Uri.parse("http://www.foxplay.com/ar/show/6980-los-simpson?gclid=CPa-7N-y7MUCFYMSHwodNLYAKQ"))
.build();
this._btnShare = (ShareButton)findViewById(R.id.share_button);
this._btnShare.setShareContent( shareContent );
_btnShare.registerCallback( this._fbCallbackManager, new FacebookCallback<Sharer.Result>() {
@Override
public void onSuccess(Sharer.Result result) {
Log.v("MyApp", "Share success!"); //Showed if I press the share or the cancel button
}
@Override
public void onCancel() {
Log.v("MyApp", "Share canceled"); //Only showed when I press the close button
}
@Override
public void onError(FacebookException e) {
Log.v("MyApp","Share error: " + e.toString());
}
});
}
The _fbCallbackManager is created in another method that initializes everything in the onCreate method from the activity.
http://imgur.com/VbMee31
The "Cancelar" button only respond to the onSuccess callback inspite of does not post the share content. The "close" button works ok.
According to THIS it is not a bug and it should stay that way.
The only way to know if the user accepted the publishing is to check for the postID on the result.
You will only have a postID if the user didn't cancel AND if the user is logged in to your app AND it has publish permissions. Otherwise it will always be null.
Yeah I know, it sucks.
private boolean hasPublishPermission()
{
AccessToken accessToken = AccessToken.getCurrentAccessToken();
return accessToken != null && accessToken.getPermissions().contains("publish_actions");
}
private void postStatusUpdate()
{
if(hasPublishPermission())
{
Log.d("PostStatus", "Ist");
Profile profile = Profile.getCurrentProfile();
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentTitle("Hello Facebook")
.setContentDescription( "The 'Hello Facebook' sample showcases simple Facebook integration")
.setContentUrl(Uri.parse("http://developers.facebook.com/docs/android"))
.build();
if(ShareDialog.canShow(ShareLinkContent.class))
{
Log.d("PostStatus", "2nd");
ShareDialog shareDialog = new ShareDialog(instance);
shareDialog.registerCallback(callbackManager, shareCallback);
}
else if (profile != null)
{
Log.d("PostStatus", "3rdt");
ShareApi.share(linkContent, shareCallback);
}
}
else
{
LoginManager.getInstance().logInWithPublishPermissions(this, Arrays.asList("publish_actions"));
}
}
private FacebookCallback<Sharer.Result> shareCallback = new FacebookCallback<Sharer.Result>()
{
@Override
public void onSuccess(Result result) {
// TODO Auto-generated method stub
}
@Override
public void onError(FacebookException error) {
// TODO Auto-generated method stub
}
@Override
public void onCancel() {
// TODO Auto-generated method stub
}
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With