How to create an app on Facebook to share posts on the social network

I want to put a sharing option in an application of mine and I noticed that addThis has an app on Facebook for this type of action but in the post there on the person's profile is the icon with a link and AddThis information and let's say I do not want to do "advertising" and it is not

I've looked for tutorial on Google and did not find, even tried to do it alone there on Facebook Developer but did not find out how (it is very complicated there '-').

I already have the app, I just want to know how I do the method of sharing the posts and if I'm not mistaken I think you can put a sentence in the box where the user will type something, that would be more or less like this: insert the description of the image here

Google + has an api to share posts within the page even using Javascript, does Facebook have that too?

Author: Iago Bruno, 2014-04-10

1 answers

The best - and most correct-way to do this is by using the Facebook JavaScript SDK. Take a look at the documentation before you start which is very worthwhile. It's very didactic.

Starting JS SDK

  • create a div # fb-root
  • include Facebook JavaScript
  • replace {your-app-id} with your application ID
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : '{your-app-id}',
      status     : true,
      xfbml      : true
    });
  };

  (function(d, s, id){
     var js, fjs = d.getElementsByTagName(s)[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement(s); js.id = id;
     js.src = "//connect.facebook.net/en_US/all.js";
     fjs.parentNode.insertBefore(js, fjs);
   }(document, 'script', 'facebook-jssdk'));
</script>

Share

function share() {
FB.ui(
  {
   method: 'feed', //Método para postar no Mural
   name: 'Título do conteúdo',
   caption: 'Linha abaixo do conteúdo. Não obrigatório.',
   description: 'Descrição. Recomendado no máximo 255 caracteres.',
   link: 'http://google.com/', //Link a ser compartilhado
   picture: 'http://google.com/logo.png' //Imagem do Share
  },
  function(response) {
     console.log(response); //Callback da função.
  }
);
}
</script>

JavaScript Documentation: https://developers.facebook.com/docs/javascript

Feed and Dialogs: https://developers.facebook.com/docs/sharing/reference/feed-dialog

 2
Author: Raul Mangolin, 2014-04-12 17:29:04