-1

我目前正在應用程序上自動發佈在Facebook牆上。 我經歷了所有討論這類應用程序的博客和文章。 最後我拿出了這個結果。首先,我必須對用戶進行認證,並授予如顯示在下面我的JavaScript代碼所需的權限:Facebook用戶牆上的帖子發生了重大變化

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml"> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 
<title>Title</title> 
     <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/> 
     <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script> 
     <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> 
</head> 
<body> 

<div id="fb-root"></div> 
<script type="text/javascript"> 

$(document).ready(function(){ 


var appId = "xxxxxxxxxxxxx"; 
var redirectUrl = "http://www.mydomain.com"; 

if (0 <= window.location.href.indexOf ("error_reason")) 
{ 
$(document.body).append ("<p>Authorization denied!</p>"); 
return; 
} 

window.fbAsyncInit = function(){ 

FB.init({ 
appId : appId, 
status : true, 
cookie : true, 
oauth : true, 
channel: true, 
channelURL: "http://www.mydomain.com/channel/" 
}); 


FB.getLoginStatus (onCheckLoginStatus); 
}; 


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


function onCheckLoginStatus (response) 
{ 
if (response.status != "connected") 
{ 
top.location.href = "https://www.facebook.com/dialog/oauth?client_id=" + appId + "&redirect_uri=" + encodeURIComponent (redirectUrl) + "&scope=publish_stream,email,user_birthday,publish_actions,offline_access"; 
} 
else 
{ 
// Start the application (this is just demo code)! /////////////////////////////////// 
$(document.body).append ("<p>Authorized!</p>"); 
FB.api('/me', function (response) { 
$(document.body).append ("<pre>" + JSON.stringify (response, null, "\t") + "</pre>"); 
}); 
////////////////////////////////////////////////////////////////////////////////////// 
} 
} 
}); 

</script> 
</body> 
</html> 

用戶的會話後已成功通過驗證,他接受了我的權限請求後,替他說到到我從一個站點移動到另一個站點兩週以上的最困難的代碼。但它沒用。

我發現下面的代碼發佈帖子,但僅在當前登錄用戶的牆:

<script type="text/javascript"> 

    function updateStatusViaJavascriptAPICalling(){ 
     var status = document.getElementById('status').value; 
      FB.api('/me/feed', 'post', { message: status }, function(response) { 
       if (!response || response.error) { 
        alert('Error occured'); 
       } else { 
        alert('Status updated Successfully'); 
       } 
      }); 
    } 

它的工作原理就像一個魅力,但是當我改變/me/feed到另一個Facebook的UID,還是說,出版,因爲這其他用戶的應用程序不起作用。然而,我試圖把應用程序訪問令牌和用戶訪問令牌,並將post更改爲PHP feed dialog,但也是徒勞。

我試過所有代碼PHP或JavaScript來完成這項工作,但不幸的是沒有工作。特別是在Facebook阻止應用程序開發者張貼在朋友的牆上之後。

我只需要代表我的用戶在他們的牆上發帖,即使他們不在線。我怎樣才能做到這一點?

+0

[發佈到朋友的Feed停止在2013年2月6日停止工作](http://facebook.stackoverflow.com/questions/14792062/posting-to-friends-feed-stopped-working- on-feb-6th-2013) – Igy 2013-02-11 05:14:09

+0

感謝MIchael的評論,但在你提到的文章中,我沒有得到明確的答案。我如何轉換這個'如果你想讓人們發佈到他們的朋友的時間表,請調用提要對話框。通過用戶提及標記或動作標記的朋友的故事將顯示在朋友的時間軸上(假設朋友批准標籤)'成爲工作代碼,以便再次發佈給用戶牆壁 – 2013-02-11 05:53:52

回答

0

您不能通過圖形API發佈給用戶的朋友。唯一的方法是調用Javascript SDK Feed對話框。

關於訪問令牌,您可以爲長壽命的訪問令牌[持續60天有效期]擴展短期訪問令牌。更多信息:http://developers.facebook.com/roadmap/offline-access-removal/

+0

感謝Abhas的回覆。但我仍然是新手的編碼。您能否通過給我一段代碼來實現這一點,讓我明確聲明這個語句「調用Javascript SDK Feed Dialog」。
關於訪問令牌,哪一個應該用於發佈到用戶牆上,** App訪問令牌**或**用戶訪問令牌** – 2013-02-11 07:38:03

+0

@AmrAli這裏是Feed對話框的示例:http://stackoverflow.com/questions/11287577/simple-facebook-javascript-post-to-stream-example/11288325#11288325 – Philip 2013-02-11 09:01:31

+0

@Philip「Feed對話框提示用戶發佈個人故事」,用戶必須登錄Facebook。我不想提示用戶。我想發佈沒有用戶提示和當用戶離線 – 2013-02-11 09:07:58

相關問題