Facebook Graph API - 获取与页面/组照片相同的数量

时间:2011-08-08 15:27:44

标签: facebook facebook-graph-api count facebook-like photos

我一直在测试图API并遇到了问题。如何从页面/组的照片中计算出来?

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

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

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

4 个答案:

答案 0 :(得分:28)

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

访问图表上的页面

转到页面的网址

获取网页的ID

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

网址末尾的数字是网页的ID。获取该ID并将其与图表资源管理器(here)一起使用,或者只访问它directly

访问该网页的相册

现在将相册附加到该网址会为您提供该网页的所有相册,包括墙照片:

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 名称。使用这两个字段,您可以选择包含所需照片的相册。这个结果的第一张专辑是“将开发者的爱情带到欧洲”。让我们看一下这张专辑的照片。

查看照片

如果到目前为止你已经按照了答案,下一步应该是相当明显的。使用所需相册的 ID ,并将照片附加到图表网址:

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

看到照片喜欢

就像选择相册一样,只需在上一步的输出中使用一个ID,然后在网址上添加即可看到喜欢的照片:

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"
      },

使用此输出,您只需计算数据数组中的条目数即可获得相同的数量。


请注意,所有这一切都可以通过点击输出框中的ID和连接边栏( 除了用于最后/喜欢的连接,使用graph explorer来实现所有这一切,希望是很快就添加了。我希望这会有所帮助。另外,你不需要访问令牌来执行任何操作,因为页面是公开的。希望这有帮助!

答案 1 :(得分: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
        }
      }
    }

答案 2 :(得分:1)

/ me / feed返回LIKES字段

我使用了一个解决方案,我只是在数组中找到显示LIKES

的项目数
Object.keys(item.likes.data).length

这将返回"长度"对象的数量 - 等于喜欢的数量。

答案 3 :(得分:-1)

http://graph.facebook.com/223766074374957

响应中有喜欢的属性

{
   "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
   }
}