2012-02-01 64 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

相关问题