Facebook分享按钮参数不起作用

时间:2014-04-19 10:41:29

标签: php facebook facebook-sharer

我想添加一个facebook分享按钮,但弹出窗口并没有显示正确的参数。这是我的代码:

<?php

$title=urlencode('Title of the iFrame Tab');
$url=urlencode('http://my-domain/index.php?langue=eng&table_pub=publication_eng&id=22&rub=publication');
$summary=urlencode('Custom message here');
$image=urlencode('http://my-domain/img.png');
?>
<a onClick="window.open('http://www.facebook.com/sharer.php?s=100&amp;p[title]=<?php echo $title;?>&amp;p[summary]=<?php echo $summary;?>&amp;p[url]=<?php echo $url; ?>&amp;p[images][0]=<?php echo $image;?>','sharer','toolbar=0,status=0,width=548,height=325');" href="javascript: void(0)">Share</a>

但是这段代码总是向我显示一个这样的弹出窗口: enter image description here

2 个答案:

答案 0 :(得分:0)

Facebook不再支持sharer.php中的自定义参数。

Official facebook answer

答案 1 :(得分:0)

使用facebook javascript sdk,

check this

   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'));

您的分享按钮,

  <a href="yoururl" data-image="yourimage" data-title="title" data-desc="Some description" class="fbshare">FBShare</a>

点击按钮,

   $('.fbshare').click(function(){
   elem = $(this);
   postToFeed(elem.data('title'), elem.data('desc'),
    elem.prop('href'), 
   elem.data('image'));

   return false;
    });