Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Google Feed API の使い方例
<!DOCTYPE html>
<html lang="ja">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" >
<!-- APIキーが必要な、以前の書き方
<script src="https://www.google.com/jsapi?key=<YOUR-API-KEY>" type="text/javascript"></script>
-->
<!-- APIキーが不要な、今の書き方 -->
<script src="https://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
google.load("feeds", "1");
function initialize() {
var today = new Date();
var url = 'http://feeds.feedburner.com/GoogleJapanBlog?1';
var feed = new google.feeds.Feed(url);
feed.setNumEntries(5);
feed.load(function(result){
if(!result.error){
var container = document.getElementById("feed");
var htmlstring = "";
for (var i = 0; i < result.feed.entries.length; i++)
{
htmlstring += '<div class="row">';
var entry = result.feed.entries[i];
htmlstring += '<div class="span1 pull-left"><p>';
var publishedDate= new Date(entry.publishedDate);
var pYear = publishedDate.getFullYear();
var pMonth = padZero(publishedDate.getMonth() + 1);
var pDay = padZero(publishedDate.getDate());
htmlstring += pYear + "/" + pMonth + "/" + pDay+ '</p></div>';
htmlstring += '<div class="span4"><a href="' + entry.link + '">' + entry.title + '</a></div></div>';
}
container.innerHTML = htmlstring;
}
});
}
// targetが一桁の場合、先頭にゼロを一つパディングする
function padZero(target){
if(target < 10){
return "0" + target;
}
else{
return target;
}
}
google.setOnLoadCallback(initialize);
</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