安卓.Facebook 分享对话框在 Android 6.0+ 上立即关闭 [英] Android. Facebook share dialog closes immediately on Android 6.0+

查看:36
本文介绍了安卓.Facebook 分享对话框在 Android 6.0+ 上立即关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 Facebook 分享对话框分享图片.代码如下:

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

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

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.

如何解决?

谢谢)

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)

推荐答案

如果您尝试通过 facebook 帐户使用 facebook sdk,而该 facebook 帐户不是您正在处理的项目的管理员或开发者帐户,则可能会发生上述情况.您需要转到 facebook 开发者页面并添加您尝试从中访问您的 sdk 的 facebook 帐户.

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 在打开后关闭

这篇关于安卓.Facebook 分享对话框在 Android 6.0+ 上立即关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆