2011-11-19 85 views
-2

我有一個Facebook應用程序,我想通過從我的flex應用程序調用一個php腳本將消息從應用程序直接發佈到牆上。 你能幫我解決嗎?從FB應用程序在Facebook牆上發佈一條靜態消息

function postmessage($appid) { 
    $facebook = new Facebook(array(
     'appId' => 'XXX', 
     'secret' => 'xxx', 
     'cookie' => true 
    )); 
    $session = $facebook->getSession(); 
    $attachment = array(
     'message' => 'this is my message', 
     'name' => 'This', 
     'caption' => 'Caption of the Post', 
     'link' => 'apps.facebook.com/tvtreasurehunt/', 
     'description' => 'this is a description' 
    ); 
    $result = $facebook->api('/me/feed/', 'post', $attachment); 
} 
+0

你的問題到底是什麼? – Maerlyn

+0

我想使用php sdk發佈消息。其實我有一個靈活的應用程序,然後我打電話給我想發佈消息到用戶牆的web服務。 – Prashant

回答

0

以下代碼將在用戶的牆上創建一個帖子。先決條件:您需要擁有具有publish_stream權限的有效access_token。

$context = stream_context_create(array(
    "http" => array(
    "method" => "POST", 
    "content" => http_build_query(array(
     "access_token" =>  $access_token, 
     "link"   =>  $config["fb_app_url"], 
     "name"   =>  "name", 
     "description"  =>  "description", 
    )), 
), 
)); 

file_get_contents("https://graph.facebook.com/me/feed", false, $context); 

有關更多詳細信息,請參閱官方文檔:Post on Facebook Developers

+0

你能否給我提供完整的源代碼幫助來獲取access_token,甚至設置權限。 – Prashant

+0

這不是那麼容易,這裏的文檔:http://developers.facebook.com/docs/authentication/ – Maerlyn

相關問題