Android系统。 Android 6.0+上的Facebook分享对话框立即关闭

时间:2016-10-05 09:38:17

标签: android facebook api

我正试图通过Facebook分享对话框分享图片。这是代码:

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);
        }
    }

但是有一个问题。它仅适用于:API直到6.0不包括以及如果在设备上安装Facebook应用程序。在其他情况下,它会打开并立即关闭回调中的错误。

如何解决?

感谢)

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)

1 个答案:

答案 0 :(得分:2)

如果您尝试从不是管理员的facebook帐户或您正在处理的项目的开发者帐户使用facebook sdk,则会发生以上情况。您需要访问Facebook开发者页面并添加您尝试访问sdk的Facebook帐户。

还有一个答案已经接受了相同类型的问题,如果上述方法无效,那么你可以试试这个:

Facebook android shareDialog closes after opening