Created
November 11, 2012 21:25
-
-
Save thinkAmi/4056318 to your computer and use it in GitHub Desktop.
Google Feed API の使い方例
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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