Posts to Facebook wall in eclipse without deprecated code

89 views Asked by At

All the searching on Google and stackoverflow into how to post on walls on Facebook that I can find give the same deprecated code. This is the old code for a simple wall post with a bundle.

Bundle params = new Bundle(); params.putString("name","Me");

fb.dialog(MainActivity.this, "feed", params, new DialogListener() { ,.. }

Pleeease, what would be the exact replacement for this with updated code.

1

There are 1 answers

0
user3583364 On

Would this be the replacement for that code,

Bundle params = new Bundle();
params.putString("name","Me");

 WebDialog feedDialog = (
    new WebDialog.FeedDialogBuilder(getActivity(),
        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(getActivity(),
                        "Posted story, id: "+postId,
                        Toast.LENGTH_SHORT).show();
                } else {
                    // User clicked the Cancel button
                    Toast.makeText(getActivity().getApplicationContext(), 
                        "Publish cancelled", 
                        Toast.LENGTH_SHORT).show();
                }
            } else if (error instanceof FacebookOperationCanceledException) {
                // User clicked the "x" button
                Toast.makeText(getActivity().getApplicationContext(), 
                    "Publish cancelled", 
                    Toast.LENGTH_SHORT).show();
            } else {
                // Generic, ex: network error
                Toast.makeText(getActivity().getApplicationContext(), 
                    "Error posting story", 
                    Toast.LENGTH_SHORT).show();
            }
        }

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