我想在我的网站上关联我的博客文章,我已经能够使用Blogger API v3.0来完成这项工作。我可以调用帖子的标题、内容和评论,但我想检索我在内容中上传的图像作为缩略图。到目前为止我使用的代码
<script>
function handlePost(response) {
document.getElementById("blogTitle").innerHTML += "<h3>" + response.title + "</h3>";
document.getElementById("blogContent").innerHTML += "<p>" + response.content + "</p>";
}
function handleComment(response) {
for (i in response.items) {
document.getElementById("blogComments").innerHTML += "<p>" + response.items[i].content + "</p>";
document.getElementById("blogComments").innerHTML += "<span>" + response.items[i].author.displayName + "</span>";
}
}
</script>
<script src="https://www.googleapis.com/blogger/v3/blogs/BLOGID/posts/POSTID/?callback=handlePost&key=APIKEY"></script>
<script src="https://www.googleapis.com/blogger/v3/blogs/BLOGID/posts/POSTID/comments?callback=handleComment&key=APIKEY"></script>
您可以使用url参数fetchImages=true
https://www.googleapis.com/blogger/v3/blogs/BLOGID/posts/POSTID/?callback=handlePost&key=APIKEY&fetchImages=true
你会得到类似的响应
"title": "Posts title",
"content": "content of the post",
"images": [{
"url": "https://1.bp.blogspot.com/image.jpeg"
}]
然后你可以检索图像,例如这个
var postImage = response.images[0].url;