2012-03-06 49 views
0

我試圖讓我的FB應用程序wallpost。我的代碼(波紋管)不會給eny erros,但它只是不會發布任何東西到牆上。有人能幫我嗎? = PWallpost問題?

應用程序文件(的index.php):

<!DOCTYPE html> 
<html xmlns:fb="http://www.facebook.com/2008/fbml"> 
<head> 
</head> 
<body> 

<div id="fb-root"></div> 
<script> 
    window.fbAsyncInit = function() { 
    FB.init({ 
     appId  : '1234567890', // App ID 
     channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File 
     status  : true, // check login status 
     cookie  : true, // enable cookies to allow the server to access the session 
     xfbml  : true // parse XFBML 
    }); 

    // Additional initialization code here 
    }; 

    // Load the SDK Asynchronously 
    (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)); 
</script> 



<a href="#" onClick="postToFacebook()">Post to Facebook</a> 

<script> 
function postToFacebook() { 
    var body = 'Reading Connect JS documentation'; 

    FB.api('/me/feed', 'post', { body: body, message: 'My message is ...' }, function(response) { 
     if (!response || response.error) { 
     alert('Error occured'); 
     } else { 
     alert('Post ID: ' + response); 
     } 
    }); 
} 
</script> 

<div id="fb-root"></div> 
<script> 
    window.fbAsyncInit = function() { 
    FB.init({ 
     appId : 'YOUR APP ID GOES HERE', 
     status : true, // check login status 
     cookie : true, // enable cookies to allow the server to access the session 
     xfbml : true // parse XFBML 
    }); 
    }; 

    (function() { 
    var e = document.createElement('script'); 
    e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js'; 
    e.async = true; 
    document.getElementById('fb-root').appendChild(e); 
    }()); 
</script> 

</body> 
</html> 

及渠道文件服務器(channel.php):

<?php 
$cache_expire = 60*60*24*365; 
header("Pragma: public"); 
header("Cache-Control: max-age=".$cache_expire); 
header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$cache_expire) . ' GMT'); 
?> 
<script src="//connect.facebook.net/en_US/all.js"></script> 
+0

我想看到一些簡單的例子,如何 可以使用的FB.login如做從應用程序使wallpost :) – WKoA 2012-03-06 07:00:35

+0

如果您console.dir從post命令的回調的響應,它顯示了什麼? – DMCS 2012-03-06 21:15:53

回答

1

爲什麼你想給init腳本Facebook的兩倍?: ) 下面是一個工作代碼的示例: How to get FB.api('/me/feed', 'post', ... to work? 介意,用戶需要先授權應用程序,然後才能進行FB.api調用。 http://developers.facebook.com/docs/reference/javascript/FB.login/ 和檢查,如果用戶使用FBgetLoginStatus()實際上與你的應用: http://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/ 希望這有助於

+0

爲什麼我需要chec用戶在Facebook應用程序內連接狀態?因爲如果用戶未登錄FB,他顯然不能向FB發佈任何內容。 – WKoA 2012-03-06 07:48:23

+0

不會工作:/ 有人可以給我工作代碼,張貼的東西牆?這給了我關於wallpost的例子,所以我可以開發我自己的應用程序:/ 如果wallpost來的PHP或JS,但完整的代碼將幫助我沒關係。 – WKoA 2012-03-06 09:40:40

+0

您的頁面在facebook應用程序中的事實並不意味着用戶授予了發佈內容的權限:)您需要這樣做,這裏有一些示例:https://developers.facebook.com/文檔/認證/ – 2012-03-06 23:06:14