I am currently working on the nightlife coordinator project and using the yelp fusion api. I have the access token but how do I use it.
I used the following code (using request):
request.get("https://api.yelp.com/v3/businesses/search?categories=bars&limit=50&location="+location+"&offset="+offset, {
auth: {
"bearer": access_token
}
}
1 Like
How do you do it without request, like with JQuery or Vanilla Javascript
I assumed you would use it with Node. Using the fetch API:
const access_token = "---------";
let myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer " + access_token);
fetch("https://cors-anywhere.herokuapp.com/https://api.yelp.com/v3/businesses/search?categories=bars&limit=50&location=New York", {
headers: myHeaders
}).then((res) => {
return res.json();
}).then((json) => {
console.log(json);
});
Note that I had to use cors-anywhere to avoid CORS issues.
Thank you so much it has been a problem I have been trying to solve for awhile
Edit: worked a treat. Thanks!