gpt4 book ai didi

javascript - 计算 Facebook 消息数

转载 作者:行者123 更新时间:2023-11-28 08:03:23 24 4
gpt4 key购买 nike

嘿,大家正在使用 facebook js sdk 来检索发送的消息数。代码是

<script>

function statusChangeCallback(response) {
console.log('statusChangeCallback');
console.log(response);

if (response.status === 'connected') {

testAPI();
} else if (response.status === 'not_authorized') {

document.getElementById('status').innerHTML = 'Please log ' +
'into this app.';
} else {

document.getElementById('status').innerHTML = 'Please log ' +
'into Facebook.';
}


}



function checkLoginState() {
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});


}



window.fbAsyncInit = function() {
FB.init({
appId : '289533237896176',
cookie : true, // enable cookies to allow the server to access
// the session
xfbml : true, // parse social plugins on this page
version : 'v2.0' // use version 2.0
});



};




(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));




function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me/inbox?limit=50',function(response) { for (var i=0;i<response.data.length;i++) {
var thread = response.data[i];

for (var j=0;j<thread.comments.data.length;j++) {
var comment = thread.comments.data[j].message;

console.log(comment);

}





}

}



);





}



</script>




<fb:login-button scope="public_profile,email,read_mailbox" onlogin="checkLoginState();">
</fb:login-button>

<div id="status">

<div id="fb-root"></div>

</div>

这成功地检索了消息..但是我需要的是找到发送的消息数..我尝试了comment.length但它没有帮助..我想找到总数发送的消息数。

我的json对象是http://pastebin.com/dnc9U4zN

这可以用js sdk来完成吗??..希望你们能帮助我..谢谢

最佳答案

obj 是你的 json 对象:

var numberOfMessages = 0;

obj.data.forEach(function(value){
value.comments.data.forEach(function(value2){
numberOfMessages++;
});
});

console.log(numberOfMessages);

关于javascript - 计算 Facebook 消息数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25097177/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com