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

1

I want to put a sharing option in a my application and I noticed that addThis has a Facebook app for this type of action but in the post there in the person's profile is the icon with a link and addThis information and let's say no I want to do "advertising" and it does not look cool for my app, I do not know, I guess.

I've already looked for a tutorial on Google and I did not find it, even tried to do it there in Facebook Developer but I did not figure out how (it's 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 I can put a phrase in the box where the user will type something, which would look something like this:

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

    
asked by anonymous 10.04.2014 / 18:54

1 answer

2

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 that is worth it. It is very didactic.

Starting the JS SDK

  • Create a div # fb-root
  • Include Facebook JavaScript
  • Replace {your-app-id} with your app 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: link

Feed and Dialogs: link

    
12.04.2014 / 19:29