Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebDialog share post on Facebook when user removes app from settings

Hi I have problem with Facebook:

Case:

1.User has no Facebook app.

2.User logins into Facebook via WebDialog

3.User gives all permissions for share, and shares post

4.User enters Facebook account, than into applications, and removes my app.

5.User tries to make share again.

6."Unknown error. Please try again later" Appears in WebDialog.

Is there a way to fix this case? I found that using ShareDialog i can avoid this problem when user has facebook app installed, but I don't know how to solve it if user has no fb app on his phone.

To show dialog I verify:

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

Than i ask for permissions if they are needed:

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

In the end i show WebDialog:

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

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

                    }

                })
                .build();
        feedDialog.show();

After showing WebDialog, it redirects to error page with "Unknow error [...]" text, i have found no error information, so I don't even know that something goes wrong.

I tried HelloFacebookSample, but there if user has no facebook app, he can't edit post in facebook dialog. I want to see Facebook dialog in both cases ( with/without fb app installed).

like image 326
Drake29a Avatar asked Dec 16 '13 10:12

Drake29a


1 Answers

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

So from the above code if the fb app is already installed it will open that app else you have to ask the user to login by performing Fb LoginButton . performClick(). so the user will be redirected to web dialog of fb login. the onLogin success call back u can share using.,

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();
}
like image 122
Tamilselvan Kalimuthu Avatar answered Oct 24 '22 20:10

Tamilselvan Kalimuthu