1

I want share content on Facebook from my app. When i click share button it should login and share content from dialog. Login is Working fine, But i don't know how share without default share button from Facebook SDK

My Facebook login code as follows

final ProfileTracker[] mProfileTracker = new ProfileTracker[1];
LoginManager.getInstance().logInWithReadPermissions(MainActivity.this, Arrays.asList("public_profile", "email"));
LoginManager.getInstance().registerCallback(callbackManager,
        new FacebookCallback<LoginResult>() {


            @Override
            public void onSuccess(LoginResult loginResult) {

            }

            @Override
            public void onCancel() {
                // App code
                Toast.makeText(MainActivity.this, "Authentication with Facebook failed!", Toast.LENGTH_LONG).show();

            }

            @Override
            public void onError(FacebookException exception) {
                // App code
                Toast.makeText(MainActivity.this, "Authentication with Facebook failed!", Toast.LENGTH_LONG).show();

            }
        });
}
Smittey
  • 2,475
  • 10
  • 28
  • 35
android
  • 441
  • 1
  • 5
  • 17
  • you can use ShareDialog just check documentation https://developers.facebook.com/docs/sharing/android – ville101 Jan 07 '16 at 09:58
  • Need to give witePermissions to share on facebook?? – android Jan 08 '16 at 06:00
  • no you dont need .. unless you need to create your own custom dialog or share programmatically without using the ShareDialog provided by facebook API. – ville101 Jan 08 '16 at 06:07

1 Answers1

2

After successful login use ShareLinkContent to share on facebook wall :

code :

 if (ShareDialog.canShow(ShareLinkContent.class)) {
                        ShareLinkContent linkContent = new   ShareLinkContent.Builder()
                                .setContentTitle("Any Title")
                               /* .setContentDescription(
                                        "'Hello Facebook'")*/
                                .setContentUrl(Uri.parse("https://www.google.com"))
                                .build();

                        shareDialog.show(linkContent);
                    }

In onSuccess method of LoginManager use this peice of code.

and initialize ShareDialog and CallbackManager in onCreate of Activity like this :

callbackManager=CallbackManager.Factory.create();
            shareDialog=new ShareDialog(this);
            shareDialog.registerCallback(callbackManager, new   FacebookCallback<Sharer.Result>() {
                @Override
                public void onSuccess(Sharer.Result result) {

                }

                @Override
                public void onCancel() {

                }

                @Override
                public void onError(FacebookException e) {

                }
            });

and onActivityResult method of Activity add callback manager :

  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent   data)
  {
    super.onActivityResult(requestCode, resultCode, data);
  callbackManager.onActivityResult(requestCode, resultCode, data);
   }
Kapil Rajput
  • 11,429
  • 9
  • 50
  • 65
  • its not sharing on my Facebook wall – android Jan 07 '16 at 10:20
  • what error is coming try to log it out in onError method of `shareDialog` – Kapil Rajput Jan 07 '16 at 10:23
  • "event.returnValue is deprecated" but i have added onActivityResult.but still same error is coming – android Jan 07 '16 at 10:24
  • Add callbackManager.onActivityResult(requestCode, resultCode, data); in onActivityResult method of Activity i am editing my answer check it out – Kapil Rajput Jan 07 '16 at 10:31
  • i have added callbackManager.onActivityResult(requestCode, resultCode, data); in onActivityResult but still same issue. and in onActivityResult resultcode is return as "-1". i get full profile info only sharing but not possible. – android Jan 08 '16 at 04:44
  • publish_actions is required to share? – android Jan 08 '16 at 05:04
  • @android check your key hashes, possibly case of key hashes mis-match and according to facebook doc **Your app does not need to request the publish_actions permission in order to use the Feed Dialog** doc url - https://developers.facebook.com/docs/facebook-login/permissions#reference-publish_actions please check your keyhashes and status of your app on facebook dev portal, app should be live http://stackoverflow.com/questions/20696738/i-am-new-how-do-i-make-my-app-live-on-fb – Kapil Rajput Jan 08 '16 at 06:17
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/100122/discussion-between-kapil-rajput-and-android). – Kapil Rajput Jan 08 '16 at 07:57