Tumblr API:有没有办法获得Tumblr帖子收到的数量?

时间:2015-05-04 12:12:01

标签: php tumblr

我正在编写一个应用程序,必须获得PHP中Tumblr帖子的喜欢数量。我正在使用Tumblr PHP library并已成功通过身份验证。我使用Client::getBlogPosts()来获取帖子列表。它返回基本上是PHP数组的信息,如:

{
    "blog_name": "jeteon",
    "id": 92729317211,
    "post_url": "http://jeteon.tumblr.com/post/92729317211/where-to-find-libxm-so-2-for-ubuntu",
    "slug": "where-to-find-libxm-so-2-for-ubuntu",
    "type": "link",
    "date": "2014-07-24 13:43:04 GMT",
    "timestamp": 1406209384,
    "state": "published",
    "format": "html",
    "reblog_key": "oA2WcGac",
    "tags": [
      "dakota",
      "ubuntu"
    ],
    "short_url": "http://tmblr.co/Z9ROeu1MN6HTR",
    "highlighted": [],
    "note_count": 0,
    "title": "Where to find libXm.so.2 for Ubuntu",
    "url": "https://packages.debian.org/wheezy/lesstif2",
    "author": null,
    "excerpt": null,
    "publisher": "packages.debian.org",
    "description": "<p>I recently had to install Dakota (<a href=\"http://dakota.sandia.gov\">http://dakota.sandia.gov</a>) and after considerable trouble with prerequisites, found that the binary install on Ubuntu requires (amonst other umentioned libraries) a shared library called libXm.so.2. The library is in a package called lesstif2 which is no longer available, it seems. You can grab the DEB on the above link though.</p>",
    "reblog": {
      "tree_html": ""
    },
    "trail": [
      {
        "blog": {
          "name": "jeteon",
          "theme": {
            "avatar_shape": "square",
            "background_color": "#FAFAFA",
            "body_font": "Helvetica Neue",
            "header_bounds": "",
            "header_image": "http://assets.tumblr.com/images/default_header/optica_pattern_10.png?_v=eafbfb1726b334d86841955ae7b9221c",
            "header_image_focused": "http://assets.tumblr.com/images/default_header/optica_pattern_10_focused_v3.png?_v=eafbfb1726b334d86841955ae7b9221c",
            "header_image_scaled": "http://assets.tumblr.com/images/default_header/optica_pattern_10_focused_v3.png?_v=eafbfb1726b334d86841955ae7b9221c",
            "header_stretch": true,
            "link_color": "#529ECC",
            "show_avatar": true,
            "show_description": true,
            "show_header_image": true,
            "show_title": true,
            "title_color": "#444444",
            "title_font": "Gibson",
            "title_font_weight": "bold"
          }
        },
        "post": {
          "id": "92729317211"
        },
        "content": "<p>I recently had to install Dakota (<a href=\"http://dakota.sandia.gov\">http://dakota.sandia.gov</a>) and after considerable trouble with prerequisites, found that the binary install on Ubuntu requires (amonst other umentioned libraries) a shared library called libXm.so.2. The library is in a package called lesstif2 which is no longer available, it seems. You can grab the DEB on the above link though.</p>",
        "is_root_item": true,
        "is_current_item": true
      }
    ]
  }

我所寻找的最接近的字段是note_count,尽管这会聚合喜欢和reblog。如果note_count为0,那么没有问题,但是当音符计数为41时,我无法判断它是否已被喜欢40次并且一次或反过来。无论哪种方式,liked字段的存在与否都已告诉您。

我尝试使用Client::getBlogLikes()方法,但检索了博客喜欢的帖子列表(用Tumblr的说法,有效地发布了创建用户喜欢的帖子),这与我正在寻找的内容相反。

我从普通互联网上获得的最好成绩是article,建议使用网址 api.tumblr.com/v2/blog/ {base-hostname} / likes?api_key = {key } ,但据我所知,这与使用Tumblr PHP库中的Client::getBlogLikes()函数相同。

有没有人知道如何获得特定帖子的收藏数量?它不需要是特定于PHP的解决方案。

2 个答案:

答案 0 :(得分:2)

如果有人在原帖后2年仍在搜索...你可以通过将&notes_info=true附加到你的api调用来实现这一点 - 将返回notes个对象的集合。如果您遍历这些,您可以计算帖子类型。从我可以看到的帖子类型有:posted(原始帖子),likereblog。希望这有帮助!

示例说明来自json响应的集合:(仅显示1个音符)

'notes': [{'avatar_shape': 'square',
           'blog_name': 'xxx',
           'blog_url': 'xxx',
           'blog_uuid': 'xxx',
           'followed': False,
           'timestamp': 1505922448,
           'type': 'like'}],

答案 1 :(得分:1)

好像Tumblr API v2 docs,不,这是不可能的。您只能计算博客总数或人们喜欢的帖子。