我试图找出如何从apprequest响应中获取数据:
function invite(provider) {
FB.ui({
method: 'apprequests',
message: 'Check this thing out!',
title: 'Request Title'
}, function(response) {
if (response && !response.error) {
console.log('3 friend invited.');
console.log(response);
} else {
console.log('You have to invite 2 friends.');
console.log(response);
}
});
}
console.log(response);
返回:
Object {
request: "667131760069164",
to: Array[1]
}
request: "667131760069164"
to: Array[1] 0: "1476807679266627"
length: 1
我想知道如何获取to:
中存储的信息来检查被邀请的人数。
思考,有人吗?
答案 0 :(得分:1)
试试这个
obj = JSON.parse(response);
console.log(obj.to[0][0]);
console.log(obj.to[0].length);
您可以访问'中的第一个值。数组由 obj.to [0] [0] 和 obj.to [0] .length
答案 1 :(得分:0)
我设法得到了我想要的结果:
if (response.to.length > 2) {
console.log('Success! You have invited ' + response.to.length + ' friends.');
} else {
console.log('You need to invite at least 3 friends')
}
感谢您的建议。