Javascript 使用Facebook用户群-发布到好友墙

Javascript 使用Facebook用户群-发布到好友墙,javascript,php,facebook,facebook-graph-api,Javascript,Php,Facebook,Facebook Graph Api,我有一组Facebook用户,他们使用自定义的Facebook多选择器输出 输出是所选用户的列表 如何获取这些ID号,然后使用FacebookAPI将消息发布到他们的墙上?下面是我以前使用的一段PHP代码片段 $attachment = array( 'from' => $_SESSION['username'], 'access_token' => $access_token, 'message' => $message, 'name' => $tit

我有一组Facebook用户,他们使用自定义的Facebook多选择器输出

输出是所选用户的列表


如何获取这些ID号,然后使用FacebookAPI将消息发布到他们的墙上?

下面是我以前使用的一段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);
参考:

  • 确保您拥有为您的应用程序提供的有效访问令牌

  • 向用户请求“发布\u流”权限

  • 编辑:

    下面是发布到用户墙上的JavaScript方法

    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.');
             }
           }
        );  
    }
    

    下面是我以前使用的一段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);
    
    参考:

  • 确保您拥有为您的应用程序提供的有效访问令牌

  • 向用户请求“发布\u流”权限

  • 编辑:

    下面是发布到用户墙上的JavaScript方法

    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.');
             }
           }
        );  
    }
    

    谢谢-但是有人有javascript SDK示例吗?谢谢javascript编辑。我已经知道如何做到这一点了,但是,我只是对如何获取一些ID号,然后将它们推送到上面的javascript代码感兴趣。让java识别ID数组的中间环节是我正在努力的地方!谢谢-但是有人有javascript SDK示例吗?谢谢javascript编辑。我已经知道如何做到这一点了,但是,我只是对如何获取一些ID号,然后将它们推送到上面的javascript代码感兴趣。让java识别ID数组的中间环节是我正在努力的地方!