繁体   English   中英

Zomato API不起作用-ReactJs

[英]Zomato API not working - ReactJs

我很难在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网址时,都会不断收到此响应。 或通过失眠。

{
"code": 403,
"status": "Forbidden",
"message": "Invalid API Key"
}

我知道它说无效的API。 但是在登录并在Zomato开发人员门户中应用任何API密钥后,我已经获得了这些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 }); }); 

谢谢你们。

您需要在请求标头中将此键设置为此。

X-Zomato-API-Key:

样品要求:

curl -X GET --header "Accept: application/json" --header "X-Zomato-API-Key: <YOUR_API_KEY>" "https://developers.zomato.com/api/v2.1/categories"

希望这会帮助你。

似乎您缺少user-key参数及其值。 例如,URL应该类似于:

https://developers.zomato.com/api/v2.1/categories?user-key=<your API key>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM