14
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Facebook、Twitterのシェア数を取得する

Posted at

URL渡したらFacebook、Twitterのシェア数取得できるようなAPIないかなぁと思ったらあったのでメモ。

APIは予期せずドラスティックに変更されるので、突然使えなくなる可能性があります。もし使えなかったらコメントか編集リクエストをもらえると助かります。

Facebook

FQLを使います。

Request

https://graph.facebook.com/fql?q=SELECT url, normalized_url, share_count, like_count, comment_count, total_count,commentsbox_count, comments_fbid, click_count FROM link_stat WHERE url='http://konifar.hatenablog.com/entry/2015/05/02/003449'

Response (json)

{
   "data": [
      {
         "url": "http://konifar.hatenablog.com/entry/2015/05/02/003449",
         "normalized_url": "http://konifar.hatenablog.com/entry/2015/05/02/003449",
         "share_count": 499,
         "like_count": 2073,
         "comment_count": 390,
         "total_count": 2962,
         "commentsbox_count": 0,
         "comments_fbid": "948279871872016",
         "click_count": 0
      }
   ]
}

ソーシャルボタンで表示されているのは total_count なのでそれを使えばいいはずです。

Twitter

Twitterのcount APIを叩きます。

Request

https://cdn.api.twitter.com/1/urls/count.json?url=http://konifar.hatenablog.com/entry/2015/05/02/003449

Response (json)

{
    "count":2133,
    "url":"http:\/\/konifar.hatenablog.com\/entry\/2015\/05\/02\/003449\/"
}

以上。

14
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?