Facebook Graph API - 获取页面/群组照片的点赞数

发布于 2024-11-28 14:55:01 字数 346 浏览 1 评论 0原文

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

我是群组的管理员/创建者。在 https://developers.facebook.com/tools/explorer/ 中输入特定照片 ID 时它带来了该组的几乎所有数据,甚至评论,但不包括点赞数。对于类似的部分,它需要(根据文档)访问令牌,尽管任何人都可以访问该信息。

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

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

I've been testing graph API and ran into a problem. How can I get like count from photos of a page/group?

I'm administrator/creator of a group. When entering in https://developers.facebook.com/tools/explorer/ certain photo ID from that group it brings almost all data, even comments, but not the like count. For like part it needs (according to docs) access token despite the fact that anyone can access that info.

How to get access token of my page/group with required permissions and how to use it to get info I need?

If possible I would like to get JSON from a single address if it is possible.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

梓梦 2024-12-05 14:55:01

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

访问图表上的页面

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

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

网址末尾的数字是页面的 ID。获取该 ID 并将其与图形浏览器一起使用(此处)或直接访问它直接

访问页面的相册

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

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 ....

选择相册

对于data 数组有一个id 和一个name。使用这两个字段,您可以选择包含所需照片的相册。该结果中的第一张专辑是“Bringing Operations Developer Love to Europe”。我们来看看这张专辑的照片。

查看照片

如果您到目前为止已经按照答案进行操作,那么下一步应该相当明显。使用您想要的相册的 id 并将照片附加到图表网址:

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

查看照片的喜欢

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

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 和连接侧边栏( 除了最后一个 /likes 连接,希望很快就会添加。此外,您不需要访问令牌即可执行任何操作,因为页面是公开的。

This is possible with a page (even without an access token!) and here's how:

Visit the page on the graph

Get the page's id by going to the page's url:

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

The number on the end of the URL is the page's id. Take that id and use it with the graph explorer (here) or just visit it directly.

Visit the page's albums

Now appending albums to that url will give you all the albums the page has, including wall photos:

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

The output looks like this:

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

Selecting an album

For each object in the data array there is an id and a name. Using these two fields you can select the album that contains the photos you want. The first album in this result is "Bringing Operation Developer Love to Europe". Lets look at this albums photos.

Seeing Photos

If you've followed the answer up to this point the next step should be fairly obvious. Use the id for the album you want and append photos to the graph url:

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

Seeing a Photo's likes

Much like selecting an album, simply use an id in the output of the above step and append likes to the url to see a photos likes:

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

Output:

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

Using this output you can simply count the number of entries in the data array to get the like count.


Note that all of this is possible from using the graph explorer by clicking on ids in the output box and the connections sidebar (except for the last /likes connection, which will hopefully be added soon. I hope this helps. Also, you do not need an access token to do any of this because pages are public. Hope this helps!

放肆 2024-12-05 14:55:01

您可以通过结合使用 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
        }
      }
    }

You can get the comments/likes count without having to paginate through all likes by using the fields parameter in combination with likes.limit(1).summary(true). For example, a search api query for pizza below will give you all public posts and their likes count summarized:

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

results (truncated):

{
  "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
        }
      }
    }
中性美 2024-12-05 14:55:01

/me/feed 返回一个 LIKES 字段

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

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

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

/me/feed returns a LIKES field

I used a solution where I simply find the number of items in the array which display LIKES

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

This returns the "length" of an object -- which is equal to the number of likes.

趁微风不噪 2024-12-05 14:55:01

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

http://graph.facebook.com/223766074374957

there is a likes property in the response

{
   "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
   }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文