[英]Pull hi res image from reddit API
我有一个简单的脚本,可从subreddit获取图像:
唯一的问题是,它拉低分辨率的拇指,而不是高分辨率的图像。
fetch('https://www.reddit.com/r/RoomPorn.json')
.then(res => res.json())
.then(res => res.data.children)
.then(res => res.map(post => ({
author: post.data.author,
link: post.data.url,
img: post.data.thumbnail,
})))
.then(res => res.map(render))
.then(res => console.log(res))
const app = document.querySelector('#app');
const render = post => {
const node = document.createElement('div');
node.innerHTML = `
<a href="${post.link}">
<img src="${post.img}"/>
</a>`;
app.appendChild(node);
}
是否可以代替高分辨率?
感谢您的时间,
尝试:
fetch('https://www.reddit.com/r/RoomPorn.json')
.then(res => res.json())
.then(res => res.data.children)
.then(res => res.map(post => ({
author: post.data.author,
link: post.data.url,
img: post.data.preview.images[0].source.url,
})))
btw post.data.url应该是原始来源的高分辨率图像链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.