我很难尝试在reactjs中使基本的zomato api请求正常工作。
api文档看起来很简单。我正在对类别执行基本 GET 请求:https://developers.zomato.com/documentation#!/common/categories
这是我的 ReactJS 函数的样子:
componentDidMount() {
// A previous request for london restaurants
// axios.get('https://developers.zomato.com/api/v2.1/geocode?
lat=51.5138&lon=0.0984')
axios.get('https://developers.zomato.com/api/v2.1/categories')
.then(res => {
console.log(res.data);
this.setState(
{ places: res.data});
});
}
但是,当我在浏览器中点击任何 api url 时,我不断收到此响应。或者通过失眠。
{
"code": 403,
"status": "Forbidden",
"message": "Invalid API Key"
}
我知道它说 API 无效。但我在登录 Zomato 开发者门户并应用任何 API key 后获得了这些 URL。找不到任何说明来找出我哪里出错了......
谢谢, 瑞娜。
最佳答案
我明白了,答案是这样的:
const config = { headers: {'user-key': 'MY KEY HERE'} };
enter code here
axios.get('developers.zomato.com/api/v2.1/…;, config) .then(res => {
console.log(res.data.collections); this.setState( { places:
res.data.collections }); });
谢谢大家。
关于javascript - Zomato API 不工作 - ReactJs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49712562/