Facebook多次发布到墙

facebook multiple publish to wall

本文关键字:Facebook      更新时间:2023-09-26

我使用js SDK通过我在facebook上创建的应用程序从我的网站发布消息到朋友墙。上面的代码很好,当我张贴到单墙。问题我想张贴到多个墙在同一时间,没有弹出窗口或对话框出现相同的消息。我知道它必须通过循环来完成,但不能使它工作。

我的代码是

 var publish =
            {
                method: 'stream.publish',
                // display: 'popup',

                attachment: 
                {
                    name: 'name' ,
                    caption: 'www.caption.com'  ,
                    description: ('description'),
    href: 'url',
                    media: [
                  {
                    type: 'image',
           href: 'url',
                    src: 'url'
                  }
                ]                   
                }
            };
         publish.target_id =id1;
         FB.ui(publish);
         publish.target_id = id2;
         FB.ui(publish);
            return false;
        }

任何形式的帮助将不胜感激。

谢谢

由于:http://developers.facebook.com/policy/

5. You must not provide users with the option to publish more than one Stream story at a time.

你应该避免在同一时间把相同的消息发布到多个墙。

编辑:

但是如果你真的不想这么做:你不应该使用Fb.ui(),这是用于Facebook对话框。

你可以使用:

var body = 'Reading JS SDK documentation';
FB.api('/me/feed', 'post', { message: body }, function(response) {
  if (!response || response.error) {
    alert('Error occured');
  } else {
    alert('Post ID: ' + response.id);
  }
});

所以,你只需要循环你的userid,并用user_id替换"me"

最后我用下面的代码让它工作:

function  doitonfacebook(){
var receivers = document.getElementById("selected-friends").innerHTML; 
var temp = new Array();
temp = receivers.split(',');
var count =temp.length;
 for (var i = 0; i < count; i++) {
 var publish = {
     method: 'stream.publish',
     message: 'test',
     picture : 'http://www.takwing.idv.hk/facebook/demoapp_jssdk/img/logo.gif',
     link : 'http://www.test.com',
     name: 'test',
     caption: 'Caption of the Post',
     description: 'testttttt',
     actions : { name : 'testing', link : 'http://www.takwing.idv.hk/tech/fb_dev/index.php'}
   };
FB.api('/'+temp[i]+'/feed', 'post',publish, function(response) {
  if (!response || response.error) {
    alert('Error occured');
  } else {
    alert('success publishing: ' );
  }
});

        }}

感谢您的回复