FB.api后在同一时间多个ID [英] FB.api post to multiple ids at same time

查看:247
本文介绍了FB.api后在同一时间多个ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里有一个小麻烦。我不擅长的JavaScript 和所有

问题是,我试图张贴到使用 FB.api 一些的Facebook 用户。但是,只有当它只有一个朋友在一个时间工作。

下面是我的code:

  FB.api({方法:friends.get'},功能(结果){
   变种user_ids =;
   VAR totalFriends = result.length;
   VAR randNo = Math.floor(的Math.random()* totalFriends);
   VAR numFriends =结果? Math.min(1,totalFriends):1;
   如果(numFriends大于0){
   对于(VAR I = 0; I< numFriends;我++){
        user_ids + =(','+导致[randNo]);
        randNo ++;
        如果(randNo> = totalFriends){
            randNo = 0;
        }
      }
    }   FB.api(user_ids +'/饲料','后',{消息:txt2send},函数(响应){
   如果(!反应|| response.error){
    警报('发生错误');
   }其他{
  警报(后ID:'+ response.id);
  }
 });
  });

user_ids 的输出看起来像这样:,10083461349,100082391,19293822

希望你能帮助我解决这个问题。请不要参考我的任何链接的帮助,相信我,我用尽了一切。


解决方案

  

希望你能帮助我解决这个问题。请不要参考我的任何链接的帮助,相信我,我用尽了一切。


是的,当然。但是,而不是坚持什么文档说,你想创造自己的语法 - 你真的认为这是有帮助的...

一般访问图形API通过HTTP请求 / someid / someendpoint /

的尝试,是(最终)作出

的请求

  

/,10083461349,100082391,19293822 /饲料


- 这仅仅是完整的,纯属无稽之谈。你刚才的不能是在一次访问图形API列出多个ID。

如果您想要发布到多个用户的饲料,你必须做出的有一个的API调用的每一个的这些用户。

I'm having a little trouble here. I'm not good at javascript and all.

The problem is that I'm trying to post to some Facebook users using FB.api. However, it only works if it's only one friend at a time.

Here's my code:

   FB.api({ method: 'friends.get' }, function(result) { 
   var user_ids="" ;
   var totalFriends = result.length;
   var randNo = Math.floor(Math.random() * totalFriends);
   var numFriends = result ? Math.min(1,totalFriends) : 1;
   if (numFriends > 0) {
   for (var i=0; i<numFriends; i++) { 
        user_ids+= (',' + result[randNo]);
        randNo ++;
        if(randNo >= totalFriends){
            randNo = 0;
        } 
      }
    }

   FB.api(user_ids + '/feed', 'post', { message: txt2send },function(response) {
   if (!response || response.error) {
    alert('Error occured');
   } else {
  alert('Post ID: ' + response.id);
  }
 });
  });

The output of user_ids is looking like this: ,10083461349,100082391,19293822

Hope you can help me solve this. And please don't refer me any links to help, trust me, I've tried everything.

解决方案

Hope you can help me solve this. And please don't refer me any links to help, trust me, I've tried everything.

Yeah, sure. But instead of sticking to what the docs say, you’re trying to invent your own "syntax" – you really think that’s helpful …?

Accessing the Graph API generally works by making HTTP requests to /someid/someendpoint/.

But what you are trying, is to (eventually) make a request to

/,10083461349,100082391,19293822/feed

– which is just complete and utter nonsense. You just can’t access the Graph API listing multiple ids at once.

If you want to post to several user’s feeds, you have to make one API call for each one of these users.

这篇关于FB.api后在同一时间多个ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆