Facebook分享按钮和自定义文本

Nei*_*ir0 91 facebook

有没有办法让facebook分享按钮在墙上或新闻提要上发布自定义文字?

All*_*onC 92

我们使用这样的东西[在一行中使用]:

<a title="send to Facebook" 
  href="http://www.facebook.com/sharer.php?s=100&p[title]=YOUR_TITLE&p[summary]=YOUR_SUMMARY&p[url]=YOUR_URL&p[images][0]=YOUR_IMAGE_TO_SHARE_OBJECT"
  target="_blank">
  <span>
    <img width="14" height="14" src="'icons/fb.gif" alt="Facebook" /> Facebook 
  </span>
</a>
Run Code Online (Sandbox Code Playgroud)

  • 这不再有效. (73认同)
  • @tvgemert:尝试`<a class ="facebook"target ="_ blank"onclick ="return!window.open(this.href,'Facebook','width = 640,height = 300')"href ="http: //www.facebook.com/sharer/sharer.php?u=YOUR_URL">Facebook </a>`等 (28认同)
  • 你知道如何在弹出窗口或模态窗口中打开此链接吗?只是找不到一个有效的方法,它不像使用一些通用的弹出窗口代码那么简单...... (4认同)
  • 什么是`s = 100`? (2认同)

Sha*_*anK 30

要给facebook分享自定义参数,最好只给出链接,facebook会自动从你正在分享的页面中获取其标题+描述+图片.为了"帮助"facebook API找到这些东西,你可以将以下内容放在你正在共享的页面的标题中:

<meta property="og:title" content="title" />
<meta property="og:description" content="description" />
<meta property="og:image" content="thumbnail_image" />
Run Code Online (Sandbox Code Playgroud)

点击这里

如果页面不在您的控制之下,请使用AllisonC上面分享的内容.

对于弹出式modalview类型行为:

使用您自己的按钮/链接/文本,然后您可以这样使用模式视图类型的弹出窗口:

<script type= 'text/javascript'>
$('#twitterbtn-link,#facebookbtn-link').click(function(event) {
var width  = 575,
    height = 400,
    left   = ($(window).width()  - width)  / 2,
    top    = ($(window).height() - height) / 2,
    url    = this.href,
    opts   = 'status=1' +
             ',width='  + width  +
             ',height=' + height +
             ',top='    + top    +
             ',left='   + left;

window.open(url, 'twitter', opts);

return false;
});
</script>
Run Code Online (Sandbox Code Playgroud)

其中twitterbtn-link和facebookbtn-link都是锚点的ID.


Bha*_*h B 12

使用此功能派生自IJas提供的链接

function openFbPopUp() {
    var fburl = '';
    var fbimgurl = 'http://';
    var fbtitle = 'Your title';
    var fbsummary = "your description";
    var sharerURL = "http://www.facebook.com/sharer/sharer.php?s=100&p[url]=" + encodeURI(fburl) + "&p[images][0]=" + encodeURI(fbimgurl) + "&p[title]=" + encodeURI(fbtitle) + "&p[summary]=" + encodeURI(fbsummary);
    window.open(
      sharerURL,
      'facebook-share-dialog', 
      'width=626,height=436'); 
    return  false;
}
Run Code Online (Sandbox Code Playgroud)

或者,如果使用FB JavaScript SDK获得更多受控回调函数,也可以使用最新的FB.ui函数.

参考:FB.ui

    function openFbPopUp() {
        FB.ui(
          {
            method: 'feed',
            name: 'Facebook Dialogs',
            link: 'https://developers.facebook.com/docs/dialogs/',
            picture: 'http://fbrell.com/f8.jpg',
            caption: 'Reference Documentation',
            description: 'Dialogs provide a simple, consistent interface for applications to interface with users.'
          },
          function(response) {
            if (response && response.post_id) {
              alert('Post was published.');
            } else {
              alert('Post was not published.');
            }
          }
        );
    }
Run Code Online (Sandbox Code Playgroud)


Kon*_*Kon 8

你有几个选择:

  1. 使用标准FB Share按钮并通过页面上的Open Graph API和元标记设置文本.
  2. 而不是共享,使用FB.ui的stream.publish方法,让您在运行时控制URL,标题,标题,描述和缩略图.
  3. 或者使用http://www.facebook.com/sharer.php和适当的参数.

  • 你能详细说明后者吗?这些参数是什么? (2认同)

Vir*_*ala 6

您可以使用Facebook提供的异步JavaScript SDK并设置其参数值来自定义Facebook共享对话框

看看下面的代码:

<script type="text/javascript">
  $(document).ready(function(){
    $('#share_button').click(function(e){
      e.preventDefault();
      FB.ui(
        {
          method: 'feed',
          name: 'This is the content of the "name" field.',
          link: 'URL which you would like to share ',
          picture: ‘URL of the image which is going to appear as thumbnail image in share dialogbox’,
          caption: 'Caption like which appear as title of the dialog box',
          description: 'Small description of the post',
          message: ''
        }
      );
    });
  });
</script>
Run Code Online (Sandbox Code Playgroud)

在复制和粘贴以下代码之前,必须先初始化SDK并设置jQuery库.请点击这里逐步了解如何设置相同的信息.