**我正在尝试向该用户的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,
});
我们必须把朋友的ids放在这里.....
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>
答案 0 :(得分: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 App invitation request