2015-05-22 54 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