Get business rating over Google places API in Javascript (Client-Side)

34 Views Asked by At

I need to get a rating of a client and add it to a div. But i get an error in the console. How can i do this easily?

My Code:

/***** GOOGLE MY-BUSINESS / PLACES-DATA *****/
const apiKey = 'KEY-pHws-3qK0cCkhuTKRx7Zo';
const placeId = 'ID'; // Replace with the actual place ID of the company
  
const placeUrl = `https://maps.googleapis.com/maps/api/place/details/json?place_id=${placeId}&fields=name,rating&key=${apiKey}`;  
  
fetch(placeUrl)
  .then(response => response.json())
  .then(data => {
    const rating = data.result.rating;
    console.log(rating);
  })
  .catch(error => console.error('Error:', error));

The error: "Cross-Origin Request Blocked: The Same-Origin Policy disallows reading the external resource."

0

There are 0 best solutions below