【发布时间】:2020-10-10 04:10:09
【问题描述】:
我想在 react JS 中从 Yelp API 获取数据。我可以使用邮递员获取数据,但我无法使用我的代码获取任何数据。这是代码。
componentDidMount = () => {
const API_BASE_URL =
'https://cors-anywhere.herokuapp.com/https://api.yelp.com/v3/business/search?term=restaurant&location=usa';
const BEARER_TOKEN =
'mybearertoken';
fetch(`${API_BASE_URL}`, {
headers: {
Authorization: `${BEARER_TOKEN}`,
Origin: 'localhost:3000',
withCredentials: true,
},
})
.then(res => res.json())
.then(json => {
this.setState({
isLoaded: true,
items: json,
});
});
};
【问题讨论】:
标签: reactjs api yelp yelp-fusion-api