2012-02-01 62 views

回答

1

下面是一個簡單的PHP代碼片段我使用之前

$attachment = array(
    'from' => $_SESSION['username'], 
    'access_token' => $access_token, 
    'message' => $message, 
    'name' => $title, 
    'link' => $url, 
    'description' => $description, 
    'caption' => $caption, 
    'picture' => $img, 
    'privacy' => json_encode(array('value' => 'FRIENDS_OF_FRIENDS')) 
); 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/'.$userid.'/feed'); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //to suppress the curl output 
$result = curl_exec($ch); 
curl_close ($ch); 

參考:Facebook Graph API Post

  1. 確保你有一個有效的訪問令牌這是你的應用程序給定。

  2. 請求用戶的「publish_stream」權限。

編輯:

這裏是發佈到用戶的牆

function fb_publish() { 
    FB.ui(
     { 
     method: 'stream.publish', 
     message: 'Message here.', 
     attachment: { 
      name: 'Name here', 
      caption: 'Caption here.', 
      description: (
      'description here' 
      ), 
      href: 'url here' 
     }, 
     action_links: [ 
      { text: 'Code', href: 'action url here' } 
     ], 
     user_prompt_message: 'Personal message here' 
     }, 
     function(response) { 
     if (response && response.post_id) { 
      alert('Post was published.'); 
     } else { 
      alert('Post was not published.'); 
     } 
     } 
    ); 
} 
+0

感謝的JavaScript的方式 - 但沒有人有一個JavaScript SDK例子呢? – 2012-02-01 15:40:21

+0

感謝您的Javascript編輯。但是我確實知道如何做到這一點,但我只關心如何獲取一些ID號碼,然後將它們推送到上面的JavaScript代碼。 – 2012-02-02 13:09:08

+0

讓java識別ID數組的中間位置就是我掙扎的地方! – 2012-02-02 13:09:37