Skip to content

Instantly share code, notes, and snippets.

@thinkAmi
Created November 11, 2012 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thinkAmi/4056321 to your computer and use it in GitHub Desktop.
Save thinkAmi/4056321 to your computer and use it in GitHub Desktop.
Google Blogger API の使い方例
<!DOCTYPE html>
<html lang="ja">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" >
<script type="text/javascript" charset="utf-8" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script src="https://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8" src="W3CDTF.js"></script>
<script type="text/javascript">
var blogId = "20042392";
var apikey = <your api key>;
var results = "5";
var url = "https://www.googleapis.com/blogger/v2/blogs/"
+ blogId
+ "/posts?fetchBodies=false"
+ "&maxResults=" + results
+ "&key=" + apikey;
$(document).ready(function() {
$.ajax({
url: url,
dataType: "jsonp",
success: function(data, textStatus){
var items = [];
$.each(data.items, function(index, value) {
items.push('<div class="row"><div class="span1 pull-left"><p>');
// W3CDTF.jsを使って、BloggerAPIにて取得したW3CDTF形式からJavascriptの日付型を生成する
// http://www.kawa.net/works/js/date/w3cdtf.html
var publishedDate= new Date.W3CDTF();
publishedDate.setW3CDTF(value.published);
var pYear = publishedDate.getFullYear();
var pMonth = padZero(publishedDate.getMonth() + 1);
var pDay = padZero(publishedDate.getDate());
items.push(pYear + "/" + pMonth + "/" + pDay+ '</p></div>');
items.push('<div class="span4"><a href="' + value.url + '">' + value.title + '</a></div></div>');
});
$(items.join("")).appendTo("#feed");
}
});
});
// targetが一桁の場合、先頭にゼロを一つパディングする
function padZero(target){
if(target < 10){
return "0" + target;
}
else{
return target;
}
}
</script>
</head>
<body>
<div id="feed">
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment