0

**嗨,我正在尝试向用户的 30 个随机朋友发送应用请求。所以我想获取 30 个 facebook 朋友的用户 id 解析它并将 uid 输入

function sendRequestToRecipients() {
var user_ids = document.getElementsByName("user_ids")[0].value;
FB.ui({method: 'apprequests',
message: 'sample message',
to: 'id of friend1,id of friend2,id of friend 3,,,,,,,'
}, requestCallback);
}**

以下是完整的示例代码...

 

<script>
  FB.init({
    appId  : 'appid',
    frictionlessRequests: true,
  });

我们必须把朋友的身份证放在这里.....

  function sendRequestToRecipients() {
    var user_ids = document.getElementsByName("user_ids")[0].value;
    FB.ui({method: 'apprequests',
      message: 'sample message',
       to: 'id of friend,id of friend'
    }, requestCallback);
  }

  function sendRequestViaMultiFriendSelector() {
    FB.ui({method: 'apprequests',
      message: 'sample message'
    }, requestCallback);
  }

  function requestCallback(response) {
    // Handle callback here
  }
 </script>
4

1 回答 1

0
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(30,totalFriends) : 0;
       if (numFriends > 0) {
          for (var i=0; i<numFriends; i++) { 
            user_ids+= (',' + result[randNo]);
            randNo ++;
            if(randNo >= totalFriends){
                randNo = 0;
            } 
          }
        }
        profilePicsDiv.innerHTML = user_ids;
    alert(user_ids);

      });

请参阅我在Facebook 应用邀请请求中的回答

于 2012-05-28T19:35:24.320 回答