Greetings everyone! I have been utilizing the Facebook JS SDK to retrieve the number of messages sent. Below is the code snippet:
<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,
xfbml: true,
version: 'v2.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>
This successfully retrieves the messages. However, my goal is to determine the number of messages sent. I attempted using comment.length
but it did not work. I am looking to find the total number of messages sent.
Below is a link to my JSON object: http://pastebin.com/dnc9U4zN
Is it possible to achieve this using the JS SDK? Any assistance would be greatly appreciated. Thank you!