Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How post to wall facebook android-sdk:4.0.0

Please help

I hava code for button post to wall :

btnPostToWall.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        postToWall();
    }
});

public void postToWall() {
    // post on user's wall.
    facebook.dialog(this, "feed", new DialogListener() {

        @Override
        public void onFacebookError(FacebookError e) {
        }

        @Override
        public void onError(DialogError e) {
        }

        @Override
        public void onComplete(Bundle values) {
        }

        @Override
        public void onCancel() {
        }
    });

}

But I Have New Faceboof android sdk 4.0.0 and this code depreacated

How post to wall whith new library?

I read this, but I don't understand how to use

like image 216
toni7777 Avatar asked May 13 '15 20:05

toni7777


1 Answers

The official Facebook documentation on how to share from Android SDK 4.0 is located here:

https://developers.facebook.com/docs/sharing/android

That link has examples of how to share by calling the Graph API or sharing by calling the native Facebook app dialog.

Here is how I implemented the share dialog in my own app:

in the xml for the activity/fragment I added the Button

  <Button
        android:layout_width="144dp"
        android:layout_height="144dp"
        android:id="@+id/shareFacebookButton"
        android:text=""
        android:background="@drawable/facebook_button"
        android:layout_gravity="center"
        android:layout_marginBottom="6dp"
        />

Then inside the Fragment:

Button shareButton = (Button)view.findViewById(R.id.shareFacebookButton);
shareDialog = new ShareDialog(this);
callbackManager = CallbackManager.Factory.create();
shareDialog.registerCallback(callbackManager, new 

FacebookCallback<Sharer.Result>() {
    @Override
    public void onSuccess(Sharer.Result result) {}

    @Override
    public void onCancel() {}

    @Override
    public void onError(FacebookException error) {}
});

shareButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
         if (ShareDialog.canShow(ShareLinkContent.class)) {
             ShareLinkContent linkContent = new ShareLinkContent.Builder()
                .setContentTitle("Hello Facebook")
                .setContentDescription("The 'Hello Facebook' sample  showcases simple Facebook integration")

             .setContentUrl(Uri.parse("http://developers.facebook.com/android"))
                            .build();

         shareDialog.show(linkContent);
          }
     }});

Now when someone clicks on the button they will be met with the Facebook dialog like you would expect.

Hope this helps.

like image 93
Max Worg Avatar answered Sep 28 '22 16:09

Max Worg