function result_publish() {
FB.ui(
{
method: 'stream.publish',
message: '使用者預設的說話內容',
attachment: {
name: '標題',
caption: '子標題',
description: '描述',
href: '標題連結的網址',
properties: {
'項目標題': { 'text': '項目內容文字', 'href': '項目內容網址' },
'項目標題': { 'text': '項目內容文字', 'href': '項目內容網址' }
},
media: [{
type: 'image',
href: '圖片連結',
src: '圖片網址'
}]
},
action_links: [
{ text: '發佈後右下角的提示', href: '提示連結的網址' }
]
},
function(response) {
if (response && response.post_id) {
//alert('Post was published.');
} else {
//alert('Post was not published.');
}
}
);
}
發佈的內容超過某個字數時,描述以下的內文就會全部不見。如果在撰寫程式時有遇到這種狀況,可以在JavaScript SDK的宣告中加入一段程式碼:
window.fbAsyncInit = function() { //初始化登入狀態,使用JavaScript SDK
//輸入應用程式ID
FB.init({appId: '應用程式ID', status: true, cookie: true, xfbml: true});
//解決stream.publish無法輸入太多資料的bug
origPostTarget = FB.Content.postTarget;
FB.Content.postTarget = function(opts) {
opts.params = FB.JSON.flatten(opts.params);
origPostTarget(opts);
};
};