2012-05-04 43 views
1

我爲FB創建了一個小應用程序,使用FB.ui允許用戶在牆上分享它。我希望共享帖子在「評論」和「贊」旁邊顯示「共享」鏈接,就像任何常規的牆上帖子一樣。當使用FB.ui時分享鏈接到帖子

有沒有辦法用FB.ui做到這一點?

還是有一些其他的方法,仍然可以讓我定義自定義的圖像,標題,描述等到牆上的帖子?

我當前的代碼:

function share(name, description) { 
     FB.ui({ 
      method: 'feed', 
      name: name, 
      picture: '/img/fb.png', 
      link: url, 
      caption: '', 
      message: '', 
      description: description 
      }, function() { 
      }); 
    } 

回答

5

它可以與share_open_graph方法來實現。代碼應該看起來像這樣

FB.ui({ 
    method: 'share_open_graph', 
    action_type: 'og.shares', 
    action_properties: JSON.stringify({ 
     object : { 
      'og:url': 'http://astahdziq.in/', // your url to share 
      'og:title': 'Here my custom title', 
      'og:description': 'here custom description', 
      'og:image': 'http://example.com/link/to/your/image.jpg' 
     } 
    }) 
    }, 
    // callback 
    function(response) { 
    if (response && !response.error_message) { 
     // then get post content 
     alert('successfully posted. Status id : '+response.post_id); 
    } else { 
     alert('Something went error.'); 
    } 
}); 
+0

我相信在提出這個問題之後,已經添加了這個方法,但是這看起來像我當時所期待的。謝謝。 – teel

+0

我很高興如果這可以幫助別人,:) –

-1

您必須使用行動財產 看到的文檔here

+0

謝謝,但你能更具體一點,你如何使用操作屬性來啓用共享鏈接?文檔沒有提及任何關於共享鏈接的內容。 – teel

+0

action:[ {text:'Game',href:'http://www.example.com/'} ], –

+0

這隻會產生一個名爲「Game」的鏈接,轉到「example.com」。我想要做的是創建一個共享鏈接,允許用戶在自己的牆上分享帖子,就像正常狀態更新一樣。 – teel

0

對於the share action

FB.ui({ 
    method: 'share', 
    href: 'https://developers.facebook.com/docs/', 
}, function(response){}); 

要定義自定義圖片,標題,描述,請在頁面頂部使用Open Graph Tags

<meta property="og:url" content="http://samples.ogp.me/136756249803614" /> 
<meta property="og:title" content="Chocolate Pecan Pie" /> 
<meta property="og:description" content="This pie is delicious!" /> 
<meta property="og:image" content="https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-prn1/851565_496755187057665_544240989_n.jpg" /> 

的影響將是:

enter image description here