I'm trying to share image via Facebook share dialog. Here's code:
private void startFacebookShare() {
SharePhoto photo = new SharePhoto.Builder()
.setBitmap(getCapturedImage())
.build();
SharePhotoContent content = new SharePhotoContent.Builder()
.addPhoto(photo)
.build();
ShareDialog shareDialog = new ShareDialog(this);
shareDialog.registerCallback(fbManager, new FacebookCallback<Sharer.Result>() {
@Override
public void onSuccess(Sharer.Result result) {
Toast.makeText(MainActivity.this, "SUCCESS", Toast.LENGTH_SHORT).show();
}
@Override
public void onCancel() {
Toast.makeText(MainActivity.this, "ONCANCEL"), Toast.LENGTH_SHORT).show();
}
@Override
public void onError(FacebookException e) {
Toast.makeText(MainActivity.this, "ERROR", Toast.LENGTH_SHORT).show();
}
});
if(isFacebookInstalled()){
shareDialog.show(content, ShareDialog.Mode.NATIVE);
}else{
shareDialog.show(content, ShareDialog.Mode.WEB);
}
}
But there is a problem. It works only if: API till 6.0 not include and if Facebook app installed on the device. In the other cases it opens and immediately closes with erro in callback.
How to fix it?
Thanks)
ADD1 (LogCat):
10-05 08:42:43.790 2220-2220/com.industi.polmak_app W/System.err: {FacebookGraphResponseException: An active access token must be used to query information about the current user. httpResponseCode: 400, facebookErrorCode: 2500, facebookErrorType: OAuthException, message: An active access token must be used to query information about the current user.}
10-05 08:42:43.850 2220-2220/com.industi.polmak_app W/System.err: at com.facebook.internal.NativeProtocol.getExceptionFromErrorData(NativeProtocol.java:788)
10-05 08:42:43.850 2220-2220/com.industi.polmak_app W/System.err: at com.facebook.share.internal.ShareInternalUtility.handleActivityResult(ShareInternalUtility.java:166)
10-05 08:42:43.850 2220-2220/com.industi.polmak_app W/System.err: at com.facebook.share.internal.ShareInternalUtility$3.onActivityResult(ShareInternalUtility.java:258)
10-05 08:42:43.850 2220-2220/com.industi.polmak_app W/System.err: at com.facebook.internal.CallbackManagerImpl.onActivityResult(CallbackManagerImpl.java:82)
10-05 08:42:43.850 2220-2220/com.industi.polmak_app W/System.err: at com.industi.polmak_app.activities.MainActivity.onActivityResult(MainActivity.java:125)
10-05 08:42:43.850 2220-2220/com.industi.polmak_app W/System.err: at android.app.Activity.dispatchActivityResult(Activity.java:5423)
10-05 08:42:43.850 2220-2220/com.industi.polmak_app W/System.err: at android.app.ActivityThread.deliverResults(ActivityThread.java:3361)
10-05 08:42:43.850 2220-2220/com.industi.polmak_app W/System.err: at android.app.ActivityThread.handleSendResult(ActivityThread.java:3408)
10-05 08:42:43.850 2220-2220/com.industi.polmak_app W/System.err: at android.app.ActivityThread.access$1300(ActivityThread.java:135)
10-05 08:42:43.850 2220-2220/com.industi.polmak_app W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1244)
10-05 08:42:43.850 2220-2220/com.industi.polmak_app W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
10-05 08:42:43.850 2220-2220/com.industi.polmak_app W/System.err: at android.os.Looper.loop(Looper.java:136)
10-05 08:42:43.850 2220-2220/com.industi.polmak_app W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5017)
10-05 08:42:43.850 2220-2220/com.industi.polmak_app W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)
10-05 08:42:43.850 2220-2220/com.industi.polmak_app W/System.err: at java.lang.reflect.Method.invoke(Method.java:515)
10-05 08:42:43.850 2220-2220/com.industi.polmak_app W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
10-05 08:42:43.850 2220-2220/com.industi.polmak_app W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
10-05 08:42:43.850 2220-2220/com.industi.polmak_app W/System.err: at dalvik.system.NativeStart.main(Native Method)