Show facebook share dialog

2019-09-02 05:17发布

问题:

hi i am currently working on facebook sharing. i already have succeeded in posting particular params to facebook however what i did is to post it without even showing what will the post look like.. i was planning to show a share dialog but i cant seem to find a good guide on how i can implement it..

here's how i post

public void loginAndPostToWall(){
         facebook.authorize(this, PERMISSIONS, Facebook.FORCE_DIALOG_AUTH, new LoginDialogListener());
    }

    public void postToWall(String message){
        Bundle parameters = new Bundle();
                parameters.putString("message", "message");
                parameters.putString("link", "www.example.com");
                parameters.putString("name", "my name");
                parameters.putString("description", "Try me!");
                try {
                    facebook.request("me");
            String response = facebook.request("me/feed", parameters, "POST");
            Log.d("Tests", "got response: " + response);
            if (response == null || response.equals("") ||
                    response.equals("false")) {
                showToast("Blank response.");
            }
            else {
                showToast("Message Posted to your Wall");
            }
            finish();
        } catch (Exception e) {
            showToast("Failed to post to wall!");
            Log.v("hey", "exception:" + e);
            e.printStackTrace();
            finish();
        }
    }

any hints or guides will do.. thank you

回答1:

The following method will simply post to the wall like this:

Before posting to the wall, it will ask "What is in your mind" before posting. You can enter some text in that and then post. This is working perfectly for me.

public void SharetoWall() {
            Bundle params = new Bundle();
            params.putString("name", "test title");
            params.putString("description", "test desc");       
            params.putString("link", "some url");
            try{

                params.putString("picture", valuesProductImages.get(0));

            }catch(Exception e){

            }

            facebook.dialog(getParent(), "feed", params, new DialogListener() {

                public void onFacebookError(FacebookError e) {

                }

                public void onError(DialogError e) {

                }

                public void onComplete(Bundle values) {

                }

                public void onCancel() {

                }
            });

        }