Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tumblr API: Is there a way to get the number of likes a Tumblr post receives?

Tags:

php

tumblr

I am writing an application that has to get the number of likes for a Tumblr post in PHP. I am using the Tumblr PHP library and have successfully authenticated and all that. I use Client::getBlogPosts() to get a list of the posts. It returns what is essentially a PHP array with information like:

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

The closest field to what I'm looking for is note_count, although this aggregates both likes and reblogs. If the note_count is 0, then there's no problem, but when the note count is 41, I can't tell whether it has been liked 40 times and reblogged once or the converse. Either way, the presence or absence of the liked field already tells you this.

I tried using the Client::getBlogLikes() method but that retrieves a list of posts that the blog has liked (in Tumblr parlance, effectively posts that the creating user liked), which is the converse of what I'm looking for.

The best I could get from the general internet is this article, which suggests using the URL api.tumblr.com/v2/blog/{base-hostname}/likes?api_key={key}, but as far as I can tell from the code, this is the same as using the Client::getBlogLikes() function from the Tumblr PHP library.

Does anyone know a way to get the number of likes a particular post has received? It doesn't need to be a PHP-specific solution.

like image 560
jeteon Avatar asked May 04 '15 12:05

jeteon


People also ask

How do you know how many Likes you have on Tumblr?

You can view your Likes by clicking the Liked button in the right side of your Dashboard. Here, you can check out all of the posts you've liked. If you connect your Tumblr with your Facebook account, you can (optionally) automatically share the posts you Like to your Facebook Timeline. Happy Tumbling!

Does Tumblr have an API?

Tumblr also supports an API that delivers content according to the oEmbed standard. Our oEmbed API endpoint is https://www.tumblr.com/oembed , which supports post URLs in the format https://*.tumblr.com/post/* . If you're looking for documentation for the old v1 API, you can find it here.

How do I get my Tumblr API key?

If you have already registered your app and are looking for your keys you can find it at - https://www.tumblr.com/oauth/apps , it will be a list of your apps with their consumer keys and a toggle to reveal their secret keys.


2 Answers

In case anyone is still searching for this 2 years after the original post... you can do this by appending &notes_info=true to your api call - a collection of notes objects will be returned. If you iterate through these you can count the post types. From what I can see post types are: posted (the original post), like, and reblog. Hope this helps!

Example notes collection from json response: (showing only 1 note)

'notes': [{'avatar_shape': 'square',
           'blog_name': 'xxx',
           'blog_url': 'xxx',
           'blog_uuid': 'xxx',
           'followed': False,
           'timestamp': 1505922448,
           'type': 'like'}],
like image 158
Dan Avatar answered Oct 03 '22 02:10

Dan


It seems like for Tumblr API v2 docs, that no, it is not possible. You can only get a count of the total blog likes, or the posts that people liked.

like image 26
taco Avatar answered Oct 03 '22 01:10

taco