我想把这个API实现到我的网站上,这样我就可以从reddit获得随机的模因。
API是由D3vd on github (https://www.github.com/D3vd/Meme_API)制作的。
我从https://meme-api.herokuapp.com/gimme/memes ( api)获得的响应如下所示:
{
"postLink": "https://redd.it/sg8j7b",
"subreddit": "memes",
"title": "No you respect the nature now!",
"url": "https://i.redd.it/nk9eiy1nnte81.jpg",
"nsfw": false,
"spoiler": false,
"author": "Abdul_Sbeei",
"ups": 423,
"preview": ["https://preview.redd.it/nk9eiy1nnte81.jpg?width=108\u0026crop=smart\u0026auto=webp\u0026s=253fc41547e5acc1ee3efcc0a4644e8d52d67181", "https://preview.redd.it/nk9eiy1nnte81.jpg?width=216\u0026crop=smart\u0026auto=webp\u0026s=6050660429dd3a4ae6699a0f42294c04fc1fae02", "https://preview.redd.it/nk9eiy1nnte81.jpg?width=320\u0026crop=smart\u0026auto=webp\u0026s=07ff549bbd76d2f25f509cece0149e7939427edd", "https://preview.redd.it/nk9eiy1nnte81.jpg?width=640\u0026crop=smart\u0026auto=webp\u0026s=baa9e058ba9722515aefa9ab28bb95235d0e151b"]
}如何使用javascript只获得图像链接("url"),以便在我的网站上显示它?
thx预先
发布于 2022-01-30 16:29:15
使用fetch的一些非常基本的ajax代码应该足够了:
fetch('https://meme-api.herokuapp.com/gimme/memes')
.then(r=>r.json())
.then(json=>{
console.log( json.url )
})
https://stackoverflow.com/questions/70916442
复制相似问题