简体   繁体   English

Android Facebook SDK - “共享”对话框不响应取消回调

[英]Android Facebook SDK - Share dialog does not respond to cancel callback

I'm working with Facebook sdk 4.0 on my android app and I found this problem: 我在我的Android应用程序上使用Facebook sdk 4.0,我发现了这个问题:

-when I share a post, I can see the facebook interface and I can post it and cancel it perfectly. - 当我分享一个帖子时,我可以看到facebook界面,我可以发布并完全取消它。 I registered the callbacks, but if I press the cancel button, the onCancel callback is not called, the post is not published, but the onSuccess callback is called. 我注册了回调,但是如果按下取消按钮,则不会调用onCancel回调,不发布帖子,而是调用onSuccess回调。 However, if I touch the close button, everything works ok. 但是,如果我触摸关闭按钮,一切正常。

Here is my code: 这是我的代码:

 private void fbOnShare(){

    ShareLinkContent shareContent = new ShareLinkContent.Builder()
            .setContentTitle("The Simpson!")
            .setContentUrl(Uri.parse("http://www.foxplay.com/ar/show/6980-los-simpson?gclid=CPa-7N-y7MUCFYMSHwodNLYAKQ"))
            .build();


    this._btnShare = (ShareButton)findViewById(R.id.share_button);
    this._btnShare.setShareContent( shareContent );


    _btnShare.registerCallback( this._fbCallbackManager, new FacebookCallback<Sharer.Result>() {
        @Override
        public void onSuccess(Sharer.Result result) {

            Log.v("MyApp", "Share success!"); //Showed if I press the share or the cancel button

        }

        @Override
        public void onCancel() {
            Log.v("MyApp", "Share canceled"); //Only showed when I press the close button
        }

        @Override
        public void onError(FacebookException e) {
            Log.v("MyApp","Share error: " + e.toString());
        }

    });
}

The _fbCallbackManager is created in another method that initializes everything in the onCreate method from the activity. _fbCallbackManager是在另一个方法中创建的,该方法从活动初始化onCreate方法中的所有内容。

http://imgur.com/VbMee31 http://imgur.com/VbMee31

The "Cancelar" button only respond to the onSuccess callback inspite of does not post the share content. “Cancelar”按钮仅响应onSuccess回调,尽管不发布共享内容。 The "close" button works ok. “关闭”按钮工作正常。

According to THIS it is not a bug and it should stay that way. 根据这个它不是一个错误,它应该保持这种方式。

The only way to know if the user accepted the publishing is to check for the postID on the result. 了解用户是否接受发布的唯一方法是检查结果的postID。

You will only have a postID if the user didn't cancel AND if the user is logged in to your app AND it has publish permissions. 如果用户未取消并且用户已登录到您的应用并且具有发布权限,则您将只有一个postID。 Otherwise it will always be null. 否则它将始终为null。

Yeah I know, it sucks. 是的,我知道,它很糟糕。

private boolean hasPublishPermission()
    {
        AccessToken accessToken = AccessToken.getCurrentAccessToken();

        return accessToken != null && accessToken.getPermissions().contains("publish_actions");
    }

private void postStatusUpdate()
    {
        if(hasPublishPermission())
        {
            Log.d("PostStatus", "Ist");
            Profile profile = Profile.getCurrentProfile();
            ShareLinkContent linkContent = new ShareLinkContent.Builder()
            .setContentTitle("Hello Facebook")
            .setContentDescription( "The 'Hello Facebook' sample  showcases simple Facebook integration")
            .setContentUrl(Uri.parse("http://developers.facebook.com/docs/android"))
            .build();
            if(ShareDialog.canShow(ShareLinkContent.class))
            {
                Log.d("PostStatus", "2nd");
                ShareDialog shareDialog = new ShareDialog(instance);
                shareDialog.registerCallback(callbackManager, shareCallback);

            }
            else if (profile != null) 
            {
                Log.d("PostStatus", "3rdt");
                ShareApi.share(linkContent, shareCallback);
            } 
        }
        else
        {
            LoginManager.getInstance().logInWithPublishPermissions(this, Arrays.asList("publish_actions"));
        }

    }



private FacebookCallback<Sharer.Result> shareCallback = new FacebookCallback<Sharer.Result>()
                    {

                @Override
                public void onSuccess(Result result) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onError(FacebookException error) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onCancel() {
                    // TODO Auto-generated method stub

                }
                    };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM