Javascript 如何在React JS中使用Zomato API

Javascript 如何在React JS中使用Zomato API,javascript,reactjs,api,Javascript,Reactjs,Api,我正在尝试使用Zomato API搜索餐厅,现在我正在尝试搜索console.log一些数据。在文档中,它给出了这个Curl和请求URL curl -X GET --header "Accept: application/json" --header "user-key: a725a13c0e61675a1eb07e3df050cd20" "https://developers.zomato.com/api/v2.1/search" 及 我不太确定如何实现这一点。到目前为止,我试图做的是

我正在尝试使用Zomato API搜索餐厅,现在我正在尝试搜索console.log一些数据。在文档中,它给出了这个Curl和请求URL

curl -X GET --header "Accept: application/json" --header "user-key: a725a13c0e61675a1eb07e3df050cd20" "https://developers.zomato.com/api/v2.1/search"

我不太确定如何实现这一点。到目前为止,我试图做的是

    const getResturants = () => {
  const axios = require('axios');
  axios({
    method: 'GET',
    url: 'https://developers.zomato.com/api/v2.1/search',
    headers: {
      "user-key": "a725a13c0e61675a1eb07e3df050cd20",
      "content-type": "application/json"
    }
  })
    .then(response => {
      console.log(response.data.restaurants[0].restaurant.name);
    }).catch(error => {
      console.log(error);
    })
}

但我收到一条错误信息

我的怀疑点是一天允许1000个请求,当它超过限制时,请求将被阻止。因此,请确保未超过请求计数。 我使用了下面的代码,通过查找纬度和经度来获取餐厅,结果成功了。下面是我从ZomatoAPI获得结果的代码

sendGetRestaurant = async () => {
    try {
        const resp = await axios.get('https://developers.zomato.com/api/v2.1/search?lat='+this.state.Latitude+'&lon='+this.state.Longitude,{
            headers: {"user-key": "Access Key"}
          });
        console.log(resp.data);
    } catch (err) {
        console.error(err);
    }
}
下面是获取经度和纬度的代码

 getLocation() {
        navigator.geolocation.getCurrentPosition(
            (position) => {
                console.log("Latitude is :", position.coords.latitude);
                console.log("Longitude is :", position.coords.longitude);
                this.setState({
                    Latitude: position.coords.latitude,
                    Longitude: position.coords.longitude
                })
                this.sendGetRestaurant();
            },
            function (error) {
                console.error("Error Code = " + error.code + " - " + error.message);
            },
            {
                enableHighAccuracy: false,
                timeout: 10000,
                maximumAge: 10000
            }

        );
    }

然后我在componentDidMount方法中调用了它。

您收到了哪条错误消息?错误:“请求中止”createError createError.js:16 handleAbort xhr.js:73对于我来说,问题在其他地方,我不确定在哪里可以找到这个问题
 getLocation() {
        navigator.geolocation.getCurrentPosition(
            (position) => {
                console.log("Latitude is :", position.coords.latitude);
                console.log("Longitude is :", position.coords.longitude);
                this.setState({
                    Latitude: position.coords.latitude,
                    Longitude: position.coords.longitude
                })
                this.sendGetRestaurant();
            },
            function (error) {
                console.error("Error Code = " + error.code + " - " + error.message);
            },
            {
                enableHighAccuracy: false,
                timeout: 10000,
                maximumAge: 10000
            }

        );
    }