2016-11-22 57 views
1

如何將我的網站內容分享到臉書?
我已經試過SharerDialog,但是那些不顯示圖片。在臉書上分享帶有圖像的網站內容

我的代碼:

function facebook_share(){ 

    FB.init({ 
     appId  : '1884730308422253', 
     status  : true, 
     xfbml  : true, 
     version : 'v2.8' 
    }); 

    FB.ui({ 
     method: 'feed', 
     name: 'Come Listen to this Song', 
     link: 'http://192.168.0.100/catchthemyoung/student', 
     picture: 'http://192.168.0.100/catchthem/images/timeline/EPUQuotgRj.png', 
     caption: 'mywebsite.com', 
     description: 'msg', 
     message: 'msg' 
    }, 

    // callback 
    function(response) { 
     if (response && !response.error_message) { 
      alert('Posting completed.'); 
     } else { 
      alert('Error while posting.'); 
     } 
    } 
    ); 
} 
+0

該圖像需要公開可用,以便Facebook可以請求並存儲它。 'http:// 192.168.0.100 /'不可公開訪問。 – CBroe

回答

0

請確保您的域名與您的應用程序ID爲「1884730308422253」 請先添加應用程序域與網站加入平臺=>選擇的網站,並添加鏈接 https://developers.facebook.com/apps/XXXXXXXXXXXXX[Yourid]/settings/

註冊
 <div id="fb-root"></div>   
     <script> 
      window.fbAsyncInit = function() { 
       FB.init({ 
        appId: '889551921179700', 
        xfbml: true, 
        version: 'v2.8' 
       }); 
      }; 
      (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"; 
       fjs.parentNode.insertBefore(js, fjs); 
      }(document, 'script', 'facebook-jssdk')); 
     </script> 

     <span id="share_button" class="fb-btn"> 
       <div class="fb_icon"></div> 
       <span class="fb-share"> 
        <i class="fa fa-facebook"></i>&nbsp;&nbsp;Share 
       </span>     
     </span> 
     <script type="text/javascript"> 
          document.getElementById('share_button').onclick = function() { 
           FB.ui({ 
            method: 'share', 
            display: 'popup', 
            caption: 'Your Title', 
            picture: 'Your picture', 
            description: 'Your description', 
            href: 'Your link', 
           }, function (response) { 
           }); 
          } 
     </script> 
+0

已經完成了兄弟@Vishal Bareja –

+0

問題是圖像不來! @Vishal Bareja –

+0

好的感謝重播 –