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);
}
代わりに高解像度を引っ張っすることが可能ですか?ところでpost.data.urlは、元のソースから高解像度の画像リンクでなければなりません
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,
})))
:
は、try
- K
返信いただきありがとうございます。 私はあなたのスクリプトを試してみました: https://jsfiddle.net/7f0zyp3z/3/ しかし、それは、任意のアイデアを取得するために失敗しましたか? –
@kathrynmこのjsfiddleでレンダリングメソッドを呼び出すことを忘れました。試してみてください:https://jsfiddle.net/7f0zyp3z/5/ – xDreamCoding
これは私が必要としていたものです。 –