无法查询喜欢计数的多个帖子

时间:2015-02-26 15:20:34

标签: facebook facebook-graph-api

我想查询Graph API以获取一组帖子(带有ID的ID)。我们假设我有一个数组{firstId,secondId ...}。我试过的一种方法是:

v2.2/?ids=firstId,secondId...

只要我不想通过添加任何“字段”参数来获取喜欢/评论计数摘要,哪个效果很好。

?fields=likes.limit(1).summary(true),comments.limit(1).summary(true)

关于如何在一个请求中将id与字段params合并的任何想法?

2 个答案:

答案 0 :(得分:1)

在放置ID列表后添加您的查询

实施例,

?ids=80329313253_10153216064543254,80329313253_10153211628853254&fields=likes.limit(1).summary(true),comments.limit(1).summary(true)

{
  "80329313253_10153216064543254": {
    "id": "80329313253_10153216064543254", 
    "created_time": "2015-02-26T20:41:53+0000", 
    "likes": {
      "data": [
        {
          "id": "1463487230582100", 
          "name": "Anchidtha Lomthampinij"
        }
      ], 
      "paging": {
        "cursors": {
          "after": "MTQ2MzQ4NzIzMDU4MjEwMA==", 
          "before": "MTQ2MzQ4NzIzMDU4MjEwMA=="
        }, 
        "next": "https://graph.facebook.com/v2.2/80329313253_10153216064543254/likes?limit=1&summary=true&after=MTQ2MzQ4NzIzMDU4MjEwMA=="
      }, 
      "summary": {
        "total_count": 318822
      }
    }, 
    "comments": {
      "data": [
        {
          "id": "10153216063838254_10153216079943254", 
          "from": {
            "id": "704159799640259", 
            "name": "Akshatha Bhat"
          }, 
          "message": "If I owned you, you'd never have to dream about treats because I would give you them all the time Boo!", 
          "can_remove": false, 
          "created_time": "2015-02-26T20:47:39+0000", 
          "like_count": 193, 
          "user_likes": false
        }
      ], 
      "paging": {
        "cursors": {
          "after": "Mjg3OQ==", 
          "before": "Mjg3OQ=="
        }, 
        "next": "https://graph.facebook.com/v2.2/80329313253_10153216064543254/comments?limit=1&summary=true&after=Mjg3OQ=="
      }, 
      "summary": {
        "order": "ranked", 
        "total_count": 2879
      }
    }
  }, 
  "80329313253_10153211628853254": {
    "id": "80329313253_10153211628853254", 
    "created_time": "2015-02-24T20:15:34+0000", 
    "likes": {
      "data": [
        {
          "id": "744777938907452", 
          "name": "Faya Gurbanli"
        }
      ], 
      "paging": {
        "cursors": {
          "after": "NzQ0Nzc3OTM4OTA3NDUy", 
          "before": "NzQ0Nzc3OTM4OTA3NDUy"
        }, 
        "next": "https://graph.facebook.com/v2.2/80329313253_10153211628853254/likes?limit=1&summary=true&after=NzQ0Nzc3OTM4OTA3NDUy"
      }, 
      "summary": {
        "total_count": 407425
      }
    }, 
    "comments": {
      "data": [
        {
          "id": "10153211628843254_10153211643418254", 
          "from": {
            "id": "398118870328160", 
            "name": "Nicole Newell"
          }, 
          "message": "This is the most precious pup I've ever seen. Can we clone him?", 
          "can_remove": false, 
          "created_time": "2015-02-24T20:21:32+0000", 
          "like_count": 385, 
          "user_likes": false
        }
      ], 
      "paging": {
        "cursors": {
          "after": "Mzk5Nw==", 
          "before": "Mzk5Nw=="
        }, 
        "next": "https://graph.facebook.com/v2.2/80329313253_10153211628853254/comments?limit=1&summary=true&after=Mzk5Nw=="
      }, 
      "summary": {
        "order": "ranked", 
        "total_count": 3997
      }
    }
  }
}

答案 1 :(得分:0)

谢谢,CBroe指出'基本上我要问的是如何将多个查询字符串参数放入URL中,当然这是通过用&符号分隔它们来完成的。合并我的参数后,我得到了工作查询:

v2.2/?ids=firstId,secondId&fields=id,picture,likes.limit(1).summary(true)