2017-04-12 57 views
0

高分辨率图像我有一个简单的脚本来从版(Subreddit)获取图像:拉从reddit的API

唯一的问题是,它的拉动低分辨率大拇指代替高分辨率图像。

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); 

}

是否有可能拉高分辨率呢?

谢谢您的时间,

  • ķ

回答

1

尝试:

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应该从原始来源的高分辨率图像链接。

+0

非常感谢您的回复。 我试过你的脚本: https://jsfiddle.net/7f0zyp3z/3/ 但它未能获取,任何想法? –

+0

@ kathrynm你忘了在这个jsfiddle中调用你的渲染方法。试试:https://jsfiddle.net/7f0zyp3z/5/ – xDreamCoding

+1

这正是我需要的,谢谢 –