I've recently moved my app to FB SDK 4.0 and I got some weird troubles with sharing. The sharing dialog works great - I'm able to share with both Facebook app and WebDialog. However, after successful/failure sharing my callback doesn't work at all - so I can't even show a toast or log anything. Here's how I do:
shareDialog.registerCallback(fbManager, new FacebookCallback<Sharer.Result>() {
@Override
public void onSuccess(Sharer.Result result) {
// This doesn't work
Toast.makeText(f.getActivity(), "You shared this post", Toast.LENGTH_SHORT).show();
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException e) {
// This doesn't work
e.printStackTrace();
}
});
I've even tried debugging the app - no effect - this code wasn't even called.
So could you point me at what am I doing wrong or what am I missing?
Update
Since I'm using special class for working with FB SDK, here's the part of it:
private static CallbackManager fbManager;
public static CallbackManager init(Activity c) {
if (!FacebookSdk.isInitialized()) {
FacebookSdk.sdkInitialize(c);
}
return fbManager = CallbackManager.Factory.create();
}
...
public static void share(final Fragment f, final String title, final String description, final String link) {
ShareDialog shareDialog = new ShareDialog(f);
shareDialog.registerCallback(fbManager, new FacebookCallback<Sharer.Result>() {
@Override
public void onSuccess(Sharer.Result result) {
Toast.makeText(f.getActivity(), "You shared this post", Toast.LENGTH_SHORT).show();
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException e) {
e.printStackTrace();
}
});
shareDialog.show(f, composeContent(title, description, link));
And here how it looks like in fragment:
private CallbackManager callbackManager;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
callbackManager = FacebookHelper.init(getActivity());
}
...
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
callbackManager.onActivityResult(requestCode, resultCode, data);
}
private void publishStory() {
FacebookHelper.share(this,
"Title",
getResources().getString(R.string.sharing_text),
sharingLink);
}