检索发送的消息数 [英] Retrieve the number of messages send

查看:89
本文介绍了检索发送的消息数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在facebook js sdk应用程序开发中。我需要从收件箱中找到发送的Facebook消息的数量。我使用的代码是

In facebook js sdk app development..I need to find the number of facebook messages send from the inbox. The code which I am using is

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
   <body>

<script>

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

if (response.status === 'connected') {
  // Logged into your app and Facebook.
  testAPI();
} else if (response.status === 'not_authorized') {
  // The person is logged into Facebook, but not your app.
  document.getElementById('status').innerHTML = 'Please log ' +
    'into this app.';
} else {
  // The person is not logged into Facebook, so we're not sure if
  // they are logged into this app or not.
  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',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();">

<div id="status">

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

</div>

</body>

</html>

此脚本成功检索前10个消息的数量。我需要的是显示数量

This script successfully retrieves the number of first 10 messages ..what I need is to display the number of messages in total ..

推荐答案

Facebook自动将分页传送到返回项目列表的所有API请求。如果不指定页面大小,FB将应用其默认大小。从你的例子,它看起来像每页10项。
要移动到下一页,您应该使用 response.paging.next 字段 - 它包含可以使用FB生成的URL访问下一页。如果您到达最后一页 response.paging 字段将为空。

Facebook automatically applies paging to all API requests that return lists of items. If you do not specify page size FB will apply it's default size. From your example it looks like 10 items per page. For moving to the next page you should use response.paging.next field - it contains ready to use url generated by FB to access the next page. If you reach the last page response.paging field will be null.

更多关于FB规范分页的阅读

此外,如果要将页面大小调整为例如每页50个项目,您可以添加 limit = 50 到您的请求。代码将如下所示:

Additionally if you want to adjust page size to e.g. 50 items per page you can add limit=50 to your request. Code will look like:

FB.api('/me/inbox?limit=50', ...

这篇关于检索发送的消息数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆