2015-05-22 53 views
0

我正在添加Facebook Share按钮到我的网站。我可以将其设置为在帖子中添加图片,但我希望它包含视频。 如何使用FB.ui feed parameters来做到这一点?添加Facebook分享按钮和视频到网站

这里是添加图片我的工作代码:

<!-- Facebook share script --> 
<div id="fb-root"></div> 
<script>(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/sdk.js#xfbml=1&version=v2.3&appId=*********"; 
    fjs.parentNode.insertBefore(js, fjs); 
}(document, 'script', 'facebook-jssdk'));</script> 

<div class="fb-share-button" data-href="#{@project_url}" data-layout="icon"> 
     <%= image_tag "facebook.png", :class=>"social_icon" %> 
</div> 

$('.fb-share-button').click(function(e){ 
    e.preventDefault(); 
    FB.ui(
     { 
     method: 'feed', 
     name: "<%[email protected]%>", 
     link: '<%[email protected]_url%>', 
     picture: '<%[email protected]_file_url%>', 
     caption: ' ', 
     description: ' ', 
     message: '' 
    }); 
}); 

回答

0

而不是使用FB提要方法,我使用共享,这从我包括我的网页的元标记中提取。这结束了工作!

以供参考,这是它看起来像:

$('.fb-share-button').click(function(e){ 
    e.preventDefault(); 
    FB.ui({ 
     method: 'share', 
     href: '<%[email protected]_url%>', 
    }, function(response){}); 
    }); 

和我的元标签:

<!-- Facebook tags --> 
<meta property="fb:app_id"    content="811332718952118"/> 
<meta property="og:type"    content="video.other"/> 
<meta property="og:url"    content="<%[email protected]_url%>" /> 
<meta property="og:title"    content="<%[email protected]%>'s Spin" /> 
<meta property="og:description"  content=" " /> 
<meta property="og:video"    content="<%[email protected]_file_url%>" /> 
<meta property="og:video:type"   content="video/mp4" /> 
<meta property="og:video:width"  content="700"/> 
<meta property="og:video:height"  content="700"/> 
<meta property="og:image"    content="<%[email protected](:position).first.image_file_url%>" /> 
0

你需要指定的URL视频在source参数。你可以阅读更多here

source:连接到此 帖子的媒体文件(SWF或MP3)的URL。如果是SWF,则还必须指定图片以提供 视频的缩略图。

+0

感谢您的帮助 - 添加源后甚至,视频不显示在共享后 – scientiffic

+0

试试这个:http://stackoverflow.com/questions/20798314/using-facebooks-api-to-post-a-video-using-the-feed-dialog-fails – Bangdel

+0

我可能是错的,但我认为该网址对于视频必须是安全的网址,即https:// – Bangdel