从收件箱中获取邮件

时间:2012-01-31 11:36:26

标签: javascript multithreading facebook-javascript-sdk messages inbox

我对Graph API有疑问。

我使用Javascript作为API并建立一个小测试网站,您可以在其中登录,查找新消息并写入新状态。

我的问题是我无法获取消息或线程。

FB.api('/me/inbox',function(response) {  alert(response.id); } ); don't work.

有人在收件箱中收到邮件吗?

由于

1 个答案:

答案 0 :(得分:2)

/me/inbox request要求您获得read_mailbox权限。

一旦你得到了,/me/inbox请求将返回一个Thread's数组,看起来像这样;

{
  "data": [
    {
      "id": "1126884978255", 
      "from": {
        "name": "Someone's Name", 
        "id": "34723472"
      }, 
      "to": {
        "data": [
          {
            "name": "Someone's Name", 
            "id": "34723472"
          }, 
          {
            "name": "Matt Lunn", 
            "id": "560914724"
          }
        ]
      }, 
      "message": "Testing the one-ness.", 
      "updated_time": "2012-01-31T12:13:00+0000", 
      "unread": 0, 
      "unseen": 0, 
      "comments": {
        "data": [
          {
            "id": "1126884978255_6769", 
            "from": {
              "name": "Someone's Name", 
              "id": "34723472"
            }, 
            "message": "£140!?", 
            "created_time": "2012-01-31T11:33:15+0000"
          },
          {
            "id": "1126884978255_6771", 
            "from": {
              "name": "Matt Lunn", 
              "id": "560914724"
            }, 
            "message": "^^ month in advance as well", 
            "created_time": "2012-01-31T11:33:26+0000"
          }
        ]
      }, 
      "type": "thread"
    }
  ], 
  "summary": {
    "unseen_count": 0, 
    "unread_count": 21, 
    "updated_time": "2012-01-31T13:19:31+0000"
  }
}

因此,根据您所追求的ID,您必须这样做;

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];

        console.log(comment.message);
    }
} 

希望你明白了......