13

我一直在测试图形 API 并遇到了问题。如何从页面/组的照片中获得点赞数?

我是一个组的管理员/创建者。当输入来自该组的https://developers.facebook.com/tools/explorer/某些照片 ID 时,它会带来几乎所有数据,甚至评论,但不是喜欢计数。对于类似的部分,尽管任何人都可以访问该信息,但它需要(根据文档)访问令牌。

如何获取具有所需权限的页面/组的访问令牌以及如何使用它来获取我需要的信息?

如果可能的话,如果可能的话,我想从一个地址获取 JSON。

4

4 回答 4

28

这可以通过页面实现(即使没有访问令牌!),方法如下:

访问图表上的页面

通过转到页面的 url 获取页面的 id:

https://www.facebook.com/pages/platform/19292868552

URL 末尾的数字是页面的 id。获取该 ID 并将其与图形资源管理器(此处)一起使用,或者直接访问它。

访问页面的相册

现在将相册附加到该 url 将为您提供页面拥有的所有相册,包括墙上的照片:

https://graph.facebook.com/19292868552/albums

输出如下所示:

{
   "data": [
      {
         "id": "10150160810478553",
         "from": {
            "name": "Facebook Platform",
            "category": "Product/service",
            "id": "19292868552"
         },
         "name": "Bringing Operation Developer Love to Europe",
         "description": "Blog post: http://developers.facebook.com/blog/post/479\n\nVideos and presentations uploaded here: http://developers.facebook.com/videos/",
         "location": "Berlin, Paris, London",
         "link": "https://www.facebook.com/album.php?fbid=10150160810478553&id=19292868552&aid=285301",
         "cover_photo": "10150160811078553",
         "count": 32,
         "type": "normal",
         "created_time": "2011-04-06T23:05:44+0000",
         "updated_time": "2011-04-06T23:33:20+0000",
         "comments": {
         ..... etc ....

选择专辑

对于数据数组中的每个对象,都有一个id和一个name。使用这两个字段,您可以选择包含所需照片的相册。此结果中的第一张专辑是《Bringing Operation Developer Love to Europe》。让我们看看这张专辑的照片。

看照片

如果您到目前为止已经遵循了答案,那么下一步应该是相当明显的。使用所需专辑的id并将照片附加到图形 url:

https://graph.facebook.com/10150160810478553/photos

看到照片的赞

就像选择相册一样,只需在上述步骤的输出中使用一个 id 并将喜欢附加到 url 以查看喜欢的照片:

https://graph.facebook.com/10150160813853553/likes

输出:

{
   "data": [
      {
         "id": "1163036945",
         "name": "Aditya Pn"
      },
      {
         "id": "1555885347",
         "name": "Nadin M\u00f6ller"
      },
      {
         "id": "100001643068103",
         "name": "Umut Ayg\u00fcn"
      },
      {
         "id": "100000165334510",
         "name": "Alessandra Milfont"
      },
      {
         "id": "100001472353494",
         "name": "Sayer Mohammad Naz"
      },
      {
         "id": "1051008973",
         "name": "Jenson Daniel Chambi"
      },
      {
         "id": "100000233515895",
         "name": "Ruby Atiga"
      },

使用此输出,您可以简单地计算数据数组中的条目数以获得类似计数。


请注意,所有这一切都可以通过单击输出框中的 ids 和连接侧边栏(最后一个 /likes 连接除外,希望很快添加。我希望这会有所帮助。另外,你不由于页面是公开的,因此需要访问令牌来执行任何操作。希望这会有所帮助!

于 2011-08-11T16:57:58.597 回答
6

您可以通过将 fields 参数与likes.limit(1).summary(true). 例如,下面的披萨搜索 api 查询将为您提供所有公开帖子及其喜欢计数汇总:

https://graph.facebook.com/search?q=pizza&type=post&fields=id,name,likes.limit(1).summary(true)

结果(截断):

{
  "data": [
    {
      "id": "47883936273_659693910762305", 
      "name": "Instagram", 
      "created_time": "2014-02-16T01:15:29+0000", 
      "likes": {
        "data": [
          {
            "id": "100002243084532", 
            "name": "Yvette Martin"
          }
        ], 
        "paging": {
          "cursors": {
            "after": "MTAwMDAyMjQzMDg0NTMy", 
            "before": "MTAwMDAyMjQzMDg0NTMy"
          }, 
          "next": "https://graph.facebook.com/47883936273_659693910762305/likes?limit=1&summary=1&after=MTAwMDAyMjQzMDg0NTMy"
        }, 
        "summary": {
          "total_count": 13682
        }
      }
    }, 
    {
      "id": "136336876521150_314001148754721", 
      "name": "Pizza Box Turns into Plates & Storage Unit!", 
      "created_time": "2014-02-15T21:20:00+0000", 
      "likes": {
        "data": [
          {
            "id": "100005373008864", 
            "name": "Liliana Campoli"
          }
        ], 
        "paging": {
          "cursors": {
            "after": "MTAwMDA1MzczMDA4ODY0", 
            "before": "MTAwMDA1MzczMDA4ODY0"
          }, 
          "next": "https://graph.facebook.com/136336876521150_314001148754721/likes?limit=1&summary=1&after=MTAwMDA1MzczMDA4ODY0"
        }, 
        "summary": {
          "total_count": 2792
        }
      }
    }
于 2014-02-20T20:12:00.713 回答
1

/me/feed 返回 LIKES 字段

我使用了一个解决方案,我只需找到数组中显示 LIKES 的项目数

Object.keys(item.likes.data).length

这将返回对象的“长度”——它等于喜欢的数量。

于 2014-04-18T18:10:51.470 回答
-1

http://graph.facebook.com/223766074374957

响应中有一个 likes 属性

{
   "name": "Bejeweled Blitz",
   "is_published": true,
   "website": "https://apps.facebook.com/bejeweledblitz/",
   "username": "bejeweledblitz",
   "products": "Bejeweled Blitz\nBejeweled\nPlants vs. Zombies\nPeggle\nZuma\nChuzzle\nBookworm Adventures\n \nFor a complete list, please visit www.popcap.com\n ",
   "about": "We're the award-winning hit, Bejeweled Blitz! The lightning-fast puzzle game where you have just 60-seconds to match as many gems as you can! Start Blitzing now!",
   "general_info": "Speed is the name of the game in Bejeweled Blitz! Bejeweled Blitz is a speedier take on the classic Bejeweled match-3 gem game mechanic. Your goal is to make as many matches as you can in 60-seconds to really make your score soar! But you won't be going it alone! There are special ways to enhance your Bejeweled Blitz game - like Boosts (power-ups like Scrambler, which moves all the gems around the board or +5 seconds, to add 5 seconds more gem-matching time!) and the popular, Rare Gems. Rare Gems are like extra-special power-ups that can REALLY take your game to the next level!",
   "talking_about_count": 22487,
   "category": "App page",
   "id": "223766074374957",
   "link": "https://www.facebook.com/bejeweledblitz",
   "likes": 5796324,
   "cover": {
      "cover_id": 383412771743619,
      "source": "http://sphotos-c.ak.fbcdn.net/hphotos-ak-ash4/s720x720/417018_383412771743619_1056862875_n.jpg",
      "offset_y": 0
   }
}
于 2012-11-30T04:46:38.213 回答