Hatena::Grouphatenadeveloper

Hatena Star - Blog's Star Count API

en/star/apis/count

Hatena Star - Blog's Star Count API

Abstract

This document describes the Blog's Star Count API of Hatena Star.

Description

The Hatena Star Blog's Star Count API provides the total number of stars (☆s) given to entries in the blog. The number can be used to display the star count in your blog, or can be used as input to another service's API.

HTTP Requests and Responses

To retrieve the star count, please access Hatena Star server using the URL like this:

http://s.hatena.com/blog.json?uri={url}

... where {url} is the URL of the top page of the blog. For example, the following URL gives you the star count for the Hatena Star Diary, whose top page is http://d.hatena.com/hatenastar/:

http://s.hatena.com/blog.json?uri=http://d.hatena.com/hatenastar/

The API returns a JSON data like:

{
  "title":"\u306f\u3066\u306a\u30b9\u30bf\u30fc\u65e5\u8a18",
  "star_count":"72464",
  "count": {
    "yellow": 72460,
    "green": 4,
  },
  "uri":"http://d.hatena.ne.jp/hatenastar/"
}

The object contained in the JSON has following properties:

Property nameValue
titleTitle of the blog.
star_countTotal number of stars for the blog.
countNumbers of yellow and/or colored stars for this blog.
uriThe URL of the top page of the blog.

Star counts are represented as numbers or string representations of numbers in JSON data.

JSONP

Specifying the callback parameter in the query part of the API's URL, with a JavaScript callback function name as its value, a JSONP data, instead of plain JSON, is returned. For example, the URL:

http://s.hatena.com/blog.json?uri=http://d.hatena.com/hatenastar/&callback=view_star

... would return:

view_star(
  {
      "title":"\u306f\u3066\u306a\u30b9\u30bf\u30fc\u65e5\u8a18",
      "star_count":"72464",
      "count": {
        "yellow": 72460,
        "green": 4,
      },
      "uri":"http://d.hatena.ne.jp/hatenastar/"
   }
);

The following HTML fragment would print the star count for the blog:

<script>
function view_star(obj){
  document.write('Current stars: ☆'+ obj.star_count);
}
</script>
<script src="http://s.hatena.com/blog.json?uri=http://d.hatena.com/hatenastar/&amp;callback=view_star">

Path-embedded URLs

Deprecated Star counts can also be retrieved by blog URL-embedded URLs such as: http://s.hatena.ne.jp/blog.json/http://d.hatena.ne.jp/hatenastar/. However, depending on the format of original blog URL, you might not be able to retrieve star counts for the blog. Therefore this style of URLs are deprecated.

History

  • 12 September 2007 Announced.
  • 13 December 2010 Republished in Hatena Developer Center.
  • 11 April 2013 Added count property.