Reputation: 87
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)
Upvotes: 2
Views: 2026
Reputation: 146
The above can happen if you are trying to use facebook sdk from a facebook account which is not an administrator or an developer account for the project you are working on. You need to go to the facebook developers page and add the facebook account you are trying to access your sdk from.
There is also one answer which has received acceptance for the same type of issue, if the above doesnt work then you can try this:
Facebook android shareDialog closes after opening
Upvotes: 2