注:この記事は、元記事の補完的役割をしています。
- 元記事1:【変更お願い!】コピペのみではてなブログのソーシャルボタンをシェア数付きでおしゃれにするカスタマイズvol.2 - Yukihy Life
- 元記事2:はてなブログのシェア数付きソーシャルボタンカスタマイズでフラットボタンのコピペコードを追加です。(vol2) - Yukihy Life
最近、当ブログで配布しているシェアボタンで、Facebookのカウント数が取得されないといった不具合があることが分かりました。原因はFacebook側の仕様変更だそうです。(元記事の方は、修正済みです)
ということで、対処方法を書いていきたいと思います。
症状
症状は、Facebookのカウント数が取得されず、0のままになってしまうといったものでした。
これを、以下の部分を変更すると、シェア数が戻ります。
変更の仕方
記事下に、こういった記述があると思います。
Before
<!--シェア数の数字--> <script> //Facebookのシェア数を取得 function get_social_count_facebook(url, selcter) { jQuery.ajax({ url:'https://graph.facebook.com/', dataType:'jsonp', data:{ id:url }, success:function(res){ jQuery( selcter ).text( res.shares || 0 ); }, error:function(){ jQuery( selcter ).text('0'); } }); } //はてなブックマークではてブ数を取得 function get_social_count_hatebu(url, selcter) { jQuery.ajax({ url:'http://api.b.st-hatena.com/entry.count?callback=?', dataType:'jsonp', data:{ url:url }, success:function(res){ jQuery( selcter ).text( res || 0 ); }, error:function(){ jQuery( selcter ).text('0'); } }); } jQuery(function(){ get_social_count_facebook('{Permalink}', '.facebook-count'); get_social_count_hatebu('{Permalink}', '.hatebu-count'); }); </script>
この12行目にある、「res.shares」を「res.share.share_count」に、変えてください。
変更後のコードも、書いておきます。
After
<!--シェア数の数字--> <script> //Facebookのシェア数を取得 function get_social_count_facebook(url, selcter) { jQuery.ajax({ url:'https://graph.facebook.com/', dataType:'jsonp', data:{ id:url }, success:function(res){ jQuery( selcter ).text( res.share.share_count || 0 ); }, error:function(){ jQuery( selcter ).text('0'); } }); } //はてなブックマークではてブ数を取得 function get_social_count_hatebu(url, selcter) { jQuery.ajax({ url:'http://api.b.st-hatena.com/entry.count?callback=?', dataType:'jsonp', data:{ url:url }, success:function(res){ jQuery( selcter ).text( res || 0 ); }, error:function(){ jQuery( selcter ).text('0'); } }); } jQuery(function(){ get_social_count_facebook('{Permalink}', '.facebook-count'); get_social_count_hatebu('{Permalink}', '.hatebu-count'); }); </script>
と、いった形です。
最後に
以上で、変更は終了です。お手数おかけしますが、変更の方を、お願いします!!