Hey everyone,
I come to you because I have an issue that I don’t really understand. I just finished the last part of the project ( I thought so at least ) and everything render properly. But when I try to use the apply nothing change, so i check the console and i got two message that appeared :
-
GET https://cors-anywhere.herokuapp.com/https://api.yelp.com/v3/businesses/search?term=sushi&location=toronto&sort_by=best_match 403 (Forbidden)
-
VM807:1 Uncaught (in promise) SyntaxError: Unexpected token S in JSON at position 0
I don’t really understand this message so I would be really grateful if anyone could help me with our guide me to fix this bug.
Here is a part of the code from where the problem seem to come from :
const apiKey = '****'; // I have a key from Yelp
const Yelp = {
search(term, location, sortBy) {
return fetch(
`https://cors-anywhere.herokuapp.com/https://api.yelp.com/v3/businesses/search?term=${term}&location=${location}&sort_by=${sortBy}`,
{headers: {
Authorization: `Bearer ${apiKey}`
}
}).then(
response => {
return response.json()
}
).then(
jsonResponse => {
if(jsonResponse.businesses) {
return jsonResponse.businesses.map(business => ({
id : business.id,
imageSrc: business.imageSrc,
name: business.name,
address: business.address,
city: business.city,
state: business.state,
zipCode: business.zipCode,
category: business.category,
rating: business.rating,
reviewCount: business.reviewCount
}));
}
}
)
}
};
export default Yelp;
Last think, I verified the code solution and it doesn’t look like i made any error … (as far as i know ).
Thank in advance