Get Google Review API and Display the Rating and Reviews on Your Website

Where to get the Place ID?

Check this link: https://developers.google.com/maps/documentation/places/web-service/place-id

Type the place information in the input box where you need the Place ID for.

Where to find the Place Detail API?

Check this link: https://developers.google.com/maps/documentation/places/web-service/details#maps_http_places_details_fields-js

Create your API Key from this page, and click “CREATE CREDENTIALS”
Returned JSON data containing place rating and reviews data

CORS Issue

Cross-Origin Resource Sharing allows a server to indicate any origin (domain, scheme, or port) other than its own from which a browser should permit loading resources for the security implications. Read more:

try {
const url = `https://maps.googleapis.com/maps/api/place/details/json?place_id=${ID}&key=${process.env.NEXT_PUBLIC_GOOGLE_API_KEY}`;
fetch(url, {
method: 'GET',
mode: 'cors',
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Credentials': 'true',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PATCH, PUT, DELETE, OPTIONS',
'Access-Control-Allow-Headers': 'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version'
}
}).then(res => {
if (res.ok) {
return res.json();
}
});
} catch (e) {
console.log(e);
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Hanwen Zhang

Hanwen Zhang

21 Followers

Full-Stack Software Engineer at a Healthcare Tech Company | Document My Coding Journey | Improve My Knowledge | Share Coding Concepts in a Simple Way