Skip to content

Instantly share code, notes, and snippets.

@kurozumi
Last active August 29, 2015 14:25
Show Gist options
  • Save kurozumi/4f52048b484c2a15fad6 to your computer and use it in GitHub Desktop.
Save kurozumi/4f52048b484c2a15fad6 to your computer and use it in GitHub Desktop.
【javascript】コメント付きのはてなブックマークを10件取得する方法
<script>
var url = encodeURIComponent("http://www.hatena.ne.jp/");
$.ajax({
url: "http://b.hatena.ne.jp/entry/jsonlite/?url=" + url,
dataType: "jsonp",
success: function (obj) {
var title = obj.title;
var url = obj.url;
var id = obj.eid;
var img = obj.screenshot;
var page = obj.entry_url;
var cnt = 0;
for(var i in obj.bookmarks){
if(cnt >= 10)
break;
var user = obj.bookmarks[i].user; //ユーザーID
var icon = "http://cdn1.www.st-hatena.com/users/" + user.substr(0, 2) + "/" + user + "/profile.gif"; //アイコン
var com = obj.bookmarks[i].comment; //コメント
var date = obj.bookmarks[i].timestamp; //ブクマした日付
var tags = obj.bookmarks[i].tags.join(","); //タグ一覧
if(com.length == 0)
continue;
$("ul.bookmarks").append('<li class="list-group-item"><img src="' + icon + '" width="30" height="30" class="img-thumbnail" /> ' + user + ' ' + com + '(' + date + ') ' + tags + '</li>');
cnt++;
}
},
error: function () {
alert("通信に失敗しました…。");
},
complete: function () {
return false;
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment