I am trying to making a GET request to the Yelp Fusion API but I am running into some errors. Any advice?
I have the following variables:
const API_BASE_URL = "https://cors-anywhere.herokuapp.com/https://api.yelp.com/v3/businesses/search"
const CLIENT_ID = "Jb58...."
const BEARER_TOKEN = "iBp3g0T.....";
This is my function to fetch the data:
async function getData(term, location) {
const businessResponse = await fetch(`${API_BASE_URL}?term=${term}&location=${location}`, {
headers:{
Authorization: `Bearer ${BEARER_TOKEN}`,
Origin: "localhost",
withCredentials: true,
}
})
const businesses = await businessResponse.json()
console.log(businesses)
}
I added a button and an 'onClick' event handler in my React component to test this, and when I sent parameters into the function and clicked the button (to test the function), I received the following in the console:
GET https://cors-anywhere.herokuapp.com/https://api.yelp.com/v3/businesses/search?term=burgers&location=nj 403 (Forbidden)
Uncaught (in promise) SyntaxError: Unexpected token S in JSON at position 0
Aucun commentaire:
Enregistrer un commentaire