2017-07-28 73 views
0

我有facebook選項卡應用程序。並在那裏我有分享按鈕facebook分享未添加圖片

<p class="share-btn" id="button">share this</p> 

<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"; 
    fjs.parentNode.insertBefore(js, fjs); 
    }(document, 'script', 'facebook-jssdk')); 
</script> 

<script> 
    window.fbAsyncInit = function() { 
     FB.init({ 
      appId: 'app id', 
      cookie: true, 
      xfbml: true, 
      version: 'v2.8' 
     }); 

     window.facebookShare = function (callback) { 
      var id = @Model.Id; 

      var options = ({ 
       method: 'share', 
       href: 'https://www.facebook.com/my app url here&app_data=' + id 
      }), 
       status = ''; 

      FB.ui(options, function (response) { 
       console.log(response); 
       if (response && !response.error_code) { 
        status = 'success'; 
        $.event.trigger('fb-share.success'); 

       } else { 
        status = 'error'; 
        $.event.trigger('fb-share.error'); 
       } 

       if (callback && typeof callback === "function") { 
        callback.call(this, status); 
       } else { 
        return response; 
       } 
      }); 
     } 

    }; 



    $('#button').on('click', function (e) { 
     e.preventDefault(); 

     facebookShare(function (response) { 
      // simple function callback 
      //console.log(response); 
     }); 
    }); 

    // custom jQuery events 
    $(document) 
     .on('fb-share.success', function (e) { 
      window.location.href = "/Quiz/Finished"; 
     }) 
     .on('fb-share.error', function (e) { 
      //alert("fail"); 
     }); 
</script> 

此共享鏈接確定,但它沒有添加縮略圖。分享這看起來:

enter image description here

但在我的佈局,我有這些:

<meta property="og:url" content="http://www.your-domain.com/your-page.html" /> 
<meta property="og:type" content="website" /> 
<meta property="og:title" content="Your Website Title" /> 
<meta property="og:description" content="Your description" /> 
<meta property="og:image" content="https://www.codeproject.com/KB/aspnet/AspnetPaths/SelectImage.png" /> 

我該怎麼辦呢?有沒有機會使用選項傳遞圖像?

+0

如果您希望_your_網址的元標記有任何效果,那麼您必須共享_your_網址。如果您願意,可以將用戶從那裏重定向到您的頁面標籤。 – CBroe

回答