FACEBOOK 自訂分享圖片及內容至塗鴉牆

1.先至 https://developers.facebook.com 申請APP應用程式,並設定好基本資料再按開啟鈕。

2.引入SDK

window.fbAsyncInit = function() {
     FB.init({
       appId      : '你的APPID',
       xfbml      : true,
       version    : 'v3.2'
     });
     FB.AppEvents.logPageView();
   };

   (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 = "https://connect.facebook.net/en_US/sdk.js";
      fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));

3.自訂分享內容程式碼
var img = "https://fgophoto12.000webhostapp.com/"+data;
var desc = "your caption here";
var link = 'https://fgophoto12.000webhostapp.com';

// Open FB share popup
FB.ui({
 method: 'share_open_graph',
 action_type: 'og.shares',
  action_properties: JSON.stringify({
 object: {
  'og:url': link,
  'og:title': title,
  'og:description': desc,
   'og:image': img
 }
})

發表迴響