Wondering if you could help me. I'm new to reactjs and not entirely sure how to make api requests ?
Basically, I'm building an app, which uses Google apis geolocation to get the current users lat/lng.
Once I've got this lat and lng, I want to append this to my Yelp api call. So depending on where the user is, the app will then pull through relevant location related content/data from the API. EG - if I'm in London, my London lat/lng, will append to the api call.
I've got the whole location part working. My app is storing my lat and lng. But I'm not sure how to setup the Yelp api request in reactjs. I'm doing this client side. Here's the code I have at the moment:
getYelp = () => {
const params = {lat: this.state.lat, lng: this.state.lng};
Promise.props({
local: axios({
url: 'https://api.yelp.com/v3/businesses/search',
params: params,
json: true,
method: 'GET',
headers: {'user-key': 'MY-API-KEY'}
}).then(res => console.log(res.data))
.catch(err => console.log(err))
})
.then(data => {
this.setState({
yelpData: data
});
});
}
But I get the following error:
Failed to load https://api.yelp.com/v3/businesses/search: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8000' is therefore not allowed access. The response had HTTP status code 403.
Any help would be great! Google has prevented zomato api from working on my app, due to it penalizing any sites that have symantecs SSL certificates. So I have to change this....
Thank you!