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

Asked

Viewed 2,366 times

1

I want to put a share 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 profile of the person is the icon with a link and Addthis information and say I do not want to do "advertising" and it doesn’t look good for my app, I don’t know, I guess.

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

I already have the app, I just want to know how do I share the posts and if I’m not mistaken I think I can put a sentence in the box where the user will type something, that would be more or less like this: inserir a descrição da imagem aqui

Google+ has an api to share posts inside the page even using Javascript, Facebook also has this?

1 answer

2


The best - and most correct - way to do this is by using Facebook’s Javascript SDK. Take a look at documentation before starting it is well worth it. It is well didactic.

Starting the JS SDK

  • Create a div #fb-root
  • Include Javascript from Facebook
  • 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

  • I did as you said but this error appears: API Error Code: 191 API Error Description: The specified URL is not owned by the application Error Message: redirect_uri is not owned by the application. I changed the value of "link". There is a problem if the img is from another site?

  • 1

    @Iagobruno Probably the URL you are sharing is not authorized in your applications. Go to your app under Developers and go to the Settings tab. There, click Add Platform and select Website. Set up your website URL and you’re done. Now add your domain to App Domains. This will probably solve.

  • It worked the/ but only one thing, note that in this img (http://i.stack.Imgur.com/uRxwX.jpg) has a pre-written message that is defined by me, has how to do this?

  • 1

    @Iagobruno if I’m not mistaken is the property "message" in FB.ui

  • Didn’t work out =/

  • ah, it should be read here that this function has been disabled from the =/. As a final question, I would like to know how to share directly on the page (like this: http://i.stack.Imgur.com/J1cjo.png (ignore the red square))

  • @Iagobruno as well?

  • This box is in an iframe inside the page.

  • 1

    @Iagobruno you can add the Share function in the Parent(main window) and call the Parent Javascript function by iframe. //Parent.share();

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.