如何在我的网站上添加Facebook分享按钮? [英] How to add facebook share button on my website?

查看:174
本文介绍了如何在我的网站上添加Facebook分享按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码,假设工作,但不起作用。如果这有助于您,那么这样做会很棒。

 < script src ='http://connect.facebook.net /en_US/all.js'></script> 
< p>< a onclick ='postToFeed(); return false;'>< img src =images / fb.png/>< / a>< / p>
< p id ='msg'>< / p>

< script>
FB.init({appId:338334836292077,status:true,cookie:

true});

函数postToFeed(){

//调用API ...
var obj = {
方法:'feed',
redirect_uri:'https://www.facebook.com/cryswashington?fref = ts',
link:'https://developers.facebook.com/docs/reference/dialogs/',
图片:'http://fbrell.com/f8.jpg',
名称:'Facebook对话框',
标题:'参考文档',
描述:'使用对话框与用户'
};

函数回调(响应){

document.getElementById('msg')。innerHTML =Post ID:+ response ['post_id'];
}

FB.ui(obj,回调);
}

< / script>

我想在我的网站上添加Facebook分享按钮,应该将我的网站内容发布在墙上。谁想要分享它。



我已经研究了很多,但没有得到任何东西。请帮助我这个。



提前感谢

解决方案

您不需要全部那个代码。所有你需要的是以下几行:

 < a href =https://www.facebook.com/sharer/ sharer.php?u = example.orgtarget =_ blank> 
在Facebook上分享
< / a>

文档可以在 https://developers.facebook.com/docs/reference/plugins/share-links/


I have this code that suppose to work, but doesn't work. If this helps you in anyway that would be great.

<script src='http://connect.facebook.net/en_US/all.js'></script>
    <p><a onclick='postToFeed(); return false;'><img src="images/fb.png" /></a></p>
    <p id='msg'></p>

    <script> 
      FB.init({appId: "338334836292077", status: true, cookie: 

true});

      function postToFeed() {

        // calling the API ...
        var obj = {
          method: 'feed',
          redirect_uri:'https://www.facebook.com/cryswashington?fref=ts',
          link:'https://developers.facebook.com/docs/reference/dialogs/',
          picture: 'http://fbrell.com/f8.jpg',
          name: 'Facebook Dialogs',
          caption: 'Reference Documentation',
          description: 'Using Dialogs to interact with users.'
        };

        function callback(response) {

        document.getElementById('msg').innerHTML = "Post ID: " + response['post_id'];
        }

        FB.ui(obj, callback);
      }

    </script>

I want to add facebook share button on my website, that should just post my website's content on the wall. who want to share it.

I have researched a lot but did not get anything. Pleas help me in this.

Thanks in advance.

解决方案

You don't need all that code. All you need are the following lines:

<a href="https://www.facebook.com/sharer/sharer.php?u=example.org" target="_blank">
  Share on Facebook
</a>

Documentation can be found at https://developers.facebook.com/docs/reference/plugins/share-links/

这篇关于如何在我的网站上添加Facebook分享按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆