如何在javascript中查找最新的博客作者ID。自动操作帖子ID
<script>
function handleResponse(response) {
document.getElementById("title").innerHTML += "<h1>" + response.title + "</h1>";
document.getElementById("content").innerHTML += "<h1>" + response.content + "</h1>";
}
</script>
<script src="https://www.googleapis.com/blogger/v3/blogs/2057990476459552980/posts/post Id?callback=handleResponse&key=key"></script>
答案 0 :(得分:0)
如果您只想获取最新帖子的数据,则可以:
<div id="title"></div>
<div id="content"></div>
<script>
function handleResponse(response) {
var post = response.feed.entry[0];
document.getElementById("title").innerHTML += "<h1>" + post.title.$t + "</h1>";
document.getElementById("content").innerHTML += "<h1>" + post.content.$t + "</h1>";
}
</script>
<script src="https://www.blogger.com/feeds/2057990476459552980/posts/default?alt=json-in-script&max-results=1&callback=handleResponse"></script>
已更新:
为了获得多个帖子,您可以从以下代码开始。更改max-results
参数以控制帖子编号
<div id="content"></div>
<script>
function handleResponse(response) {
var page = "";
var posts = response.feed.entry;
for (var i = 0; i < posts.length; i++) {
page += "<div><h2>" + posts[i].title.$t + "</h2>" + posts[i].content.$t + "<div>";
}
document.getElementById("content").innerHTML = page;
}
</script>
<script src="https://www.blogger.com/feeds/2057990476459552980/posts/default?alt=json-in-script&max-results=5&callback=handleResponse"></script>