0

當我在文本框中鍵入一些內容並上傳圖片並提交時,帖子應該發佈在特定用戶的Facebook時間軸中。這是我編寫的代碼,但itz不起作用:通過我的網站發佈到facebook牆

<html> 
<head> 
<script src='http://connect.facebook.net/en_US/all.js'></script> 
</head> 
<body> 
<div id="fb-root"></div> 
<script> 
    window.fbAsyncInit = function() { 
    FB.init({ 
    appId  : 'App ID', // App ID 
    channelUrl : '//mynetwork.net/', // Channel File 
    status  : true, // check login status 
    cookie  : true, // enable cookies to allow the server to access the session 
    xfbml  : true // parse XFBML 
    }); 

    FB.Event.subscribe('auth.authResponseChange', function(response) { 
    if (response.status === 'connected') { 
     testAPI(); 
    } else if (response.status === 'not_authorized') { 
     FB.login(); 
    } else { 
     FB.login(); 
    } 
    }); 
    }; 

    (function(d){ 
    var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; 
    if (d.getElementById(id)) {return;} 
    js = d.createElement('script'); js.id = id; js.async = true; 
    js.src = "//connect.facebook.net/en_US/all.js"; 
    ref.parentNode.insertBefore(js, ref); 
    }(document)); 

    function testAPI() { 
    console.log('Welcome! Fetching your information.... '); 
    FB.api('/me', function(response) { 
     console.log('Good to see you, ' + response.name + '.'); 
    }); 
    } 
</script> 

<script> 
var params = {}; 
params['message'] = 'Message eqwe'; 
params['name'] = 'wqe wqeweq Name'; 
params['description'] = 'wqe wDescription'; 
params['link'] = 'https://www.facebook.com/nvidarshana?fref=ts'; 
params['picture'] = 'http://summer-mourning.zoocha.com/uploads/thumb.png'; 
params['caption'] = 'Caption'; 

FB.api('/me/feed', 'post', params, function(response) { 
    if (!response || response.error) { 
    console.log(response.error); 
    alert(response.error); 
    } else { 
    alert('Published to stream - you might want to delete it now!'); 
    } 
}); 
</script> 

<fb:login-button show-faces="true" width="200" max-rows="1"></fb:login-button> 
</body> 
</html> 

我已經更新了我的代碼,仍然歌廳錯誤

「對象{消息:‘一個積極的訪問令牌必須用於查詢當前用戶的信息’,輸入:」 OAuthException 「,code:2500}」

回答

0

如果您的用戶是在會議中,將以下代碼 -

FB.api('/My_Access_Token/feed' 

與 - 下面的代碼

FB.api('/me/feed' 
+0

欣賞!但它也給了我同樣的錯誤! – nanbatman

+0

你能告訴我確切的錯誤嗎? '的console.log(響應)'。並定義了「FB」? –

+0

'錯誤發生'這是我每次得到的。你的意思是「FB定義」,我在上面發佈了我的完整代碼。我應該如何定義FB? – nanbatman

0

插入不管你想要張貼在牆上的顯示按鈕。編輯相關文本。

<div id="fb-root"></div> 
     <script> 

window.fbAsyncInit = function() { 

FB.init({appId: "YOUR APP ID FROM STEP 3", status: true, cookie: true, 

xfbml: true}); 

}; 

(function() { 

var e = document.createElement("script"); e.async = true; 

e.src = document.location.protocol + 

"//connect.facebook.net/en_US/all.js"; 

document.getElementById("fb-root").appendChild(e); 

}()); 

function streamPublish(){ 


FB.ui(
    { 
    method: 'stream.publish',display:'popup'; 
<dd> 
    message: 'getting educated about Facebook Connect', 
    attachment: { 
     name: 'Connect', 
     caption: 'The Facebook Connect JavaScript SDK', 
     description: (
     'A small JavaScript library that allows you to harness ' + 
     'the power of Facebook, bringing the user\'s identity, ' + 
     'social graph and distribution power to your site.' 
     ),</dd> 


‘media’: [{ 'type': 'image', 


'src': 'http://www.yoursite.com/images/facebook_icon.png', 


'href': fb_root()}] , 



<dd> 
     href: 'http://github.com/facebook/connect-js' 
    }, 
    action_links: [ 
     { text: 'Code', href: 'http://github.com/facebook/connect-js' } 
    ], 
    user_message_prompt: 'Share your thoughts about Connect' 
    }, 
    function(response) { 
    if (response && response.post_id) { 
     alert('Post was published.'); 
    } else { 
     alert('Post was not published.'); 
    } 
    } 
); 

} </script> 


</dd> 
<dd></dd> 

通過鏈接調用streamPublish函數。您可以使用CSS來改變鏈接/按鈕的外觀。

<a onclick=」streamPublish();」 >Click to Publish on Facebook wall</a> 

如果沒有發佈窗口彈出,嘗試顯示設置:值「對話框」

+1

欣賞!我添加了我的APP ID並更改了圖像,並且我將鏈接更改爲'Click to Publish on Facebook wall',但點擊鏈接時沒有任何事情發生。我也檢查顯示:'對話'也.. – nanbatman