问题描述
我正在尝试根据搜索参数从Reddit获取图像。我现在可以很好地获取数据,但是我在data.preview.images[0].source.url
(Reddit确实将其埋在其中)中收到的url都以https://external-preview.redd.it/
为前缀。当我单击响应中的链接时,我收到一条禁止的消息。
我看过一些视频,人们可以检索图像,但是他们可以通过带前缀的i-reddit链接或您拥有的东西来检索图像。我在JSON响应中进行了一些挖掘,但找不到任何兼容的链接。
有什么想法吗?
编辑:
这是我的获取代码:
state = {
redditData: []
}
componentDidMount(){
fetch(`https://www.reddit.com/search.json?q=animal_crossing`)
.then(response => response.json())
.then(redditData => this.setState({redditData: redditData.data.children.slice(5,10)}))
}
itsCardTime = () => {
return this.state.redditData.map(rd => <RedditCard key={rd.id} data={rd.data}/>)
}
render(){
return(
<div className="homecontent">
<div className="homeimage">
<h1 >cute image</h1>
</div>
<div className="redditdata">
{this.itsCardTime()}
</div>
</div>
)
}
}
这是我应该渲染图像的代码:
render(){
console.log(this.props.data)
return(
<div className="redditcard">
<h5>
{this.props.data.title}
{/* {this.props.data.preview ? console.log(this.props.data.preview.images[0].resolutions[0].url) : null } */}
{/* {this.props.data.preview ? <img src={this.props.data.preview.images[0].source.url}/> : null} */}
</h5>
<p>{this.props.data.subreddit_name_prefixed}</p>
</div>
)}
}
我的回复以JSON格式返回,并且我可以对它们进行控制台记录。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)