当用户从设置中删除应用时,WebDialog在Facebook上分享帖子

Dra*_*29a 6 android share facebook

嗨,我有Facebook的问题:

案件:

1.User没有Facebook应用程序.

2.用户通过WebDialog登录Facebook

3.User提供共享的所有权限,并分享帖子

4.用户进入Facebook帐户,而不是进入应用程序,并删除我的应用程序.

5.User试图再次分享.

6."未知错误.请稍后再试"出现在WebDialog中.

有办法解决这个案子吗?我发现使用ShareDialog我可以避免这个问题,当用户安装了Facebook应用程序,但我不知道如果用户手机上没有fb应用程序如何解决它.

要显示对话框我验证:

 private boolean checkFacebookLogin(){
    Session session = Session.getActiveSession();
    if(session!=null && session.isOpened() ){
        return true;
    }
    return false;
}
Run Code Online (Sandbox Code Playgroud)

如果需要,我要求权限:

  private void performPublish() {

    Session session = Session.getActiveSession();
    pendingAction = PendingAction.POST_STATUS_UPDATE;

    if (session != null && mCurrentActivity!=null) {
        if (hasPublishPermission()) {
            // We can do the action right away.
            handlePendingAction();
        } else {
            // We need to get new permissions, then complete the action when we get called back.
            session.requestNewPublishPermissions(new Session.NewPermissionsRequest(mCurrentActivity, PERMISSIONS));
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

最后我展示了WebDialog:

  WebDialog feedDialog = (
                new WebDialog.FeedDialogBuilder(mCurrentActivity,
                        Session.getActiveSession(),
                        postParams))
                .setOnCompleteListener(new OnCompleteListener() {

                    @Override
                    public void onComplete(Bundle values,
                                           FacebookException error) {

                    }

                })
                .build();
        feedDialog.show();
Run Code Online (Sandbox Code Playgroud)

显示WebDialog后,它会重定向到错误页面,显示"Unknow error [...]"文本,我没有找到任何错误信息,所以我甚至不知道出了什么问题.

我试过HelloFacebookSample,但是如果用户没有facebook应用程序,他就无法在facebook对话框中编辑帖子.我想在两种情况下都看到Facebook对话框(安装/不安装fb app).

Tam*_*thu 1

if (FacebookDialog.canPresentShareDialog(this,
                FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) {
            FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(
                    this)
                    .setLink(// what  ever you want to share use here
                    .build();
            uiHelper.trackPendingDialogCall(shareDialog.present());

        } else {
            Session session = Session.getActiveSession();
             if (session != null && session.isOpened()) {
                Log.d("Tag", "Success!");
                publishFeedDialog();
             } else {
            //ask the user to login .
            //authButton.performClick();
            share = true;
            // }
        }
Run Code Online (Sandbox Code Playgroud)

因此,从上面的代码来看,如果 Facebook 应用程序已安装,它将打开该应用程序,否则您必须要求用户通过执行 Fb LoginButton 来登录。执行点击()。因此用户将被重定向到 Facebook 登录的 Web 对话框。onLogin成功回调你可以分享使用,

private void publishFeedDialog() {
    Bundle params = new Bundle();
    params.putString("link",
            "");
    WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(
            MenuActivity.this, Session.getActiveSession(), params))
            .setOnCompleteListener(new OnCompleteListener() {

                @Override
                public void onComplete(Bundle values,
                        FacebookException error) {
                    if (error == null) {
                        // When the story is posted, echo the success
                        // and the post Id.
                        final String postId = values.getString("post_id");
                        if (postId != null) {
                            Toast.makeText(MenuActivity.this, "Posted",
                                    Toast.LENGTH_SHORT).show();
                        } else {
                            // User clicked the Cancel button
                            Toast.makeText(
                                    MenuActivity.this
                                            .getApplicationContext(),
                                    "Publish cancelled", Toast.LENGTH_SHORT)
                                    .show();
                        }
                    } else if (error instanceof FacebookOperationCanceledException) {
                        // User clicked the "x" button
                        Toast.makeText(
                                MenuActivity.this.getApplicationContext(),
                                "Publish cancelled", Toast.LENGTH_SHORT)
                                .show();
                    } else {
                        // Generic, ex: network error
                        Toast.makeText(
                                MenuActivity.this.getApplicationContext(),
                                "Error posting story", Toast.LENGTH_SHORT)
                                .show();
                    }
                }

            }).build();
    feedDialog.show();
}
Run Code Online (Sandbox Code Playgroud)