Struggling to display the Google reviews for my company on our website, I can't seem to make it work. I've attempted to use this code:
<script>
$(function() {
var people = [];
$.getJSON('https://maps.googleapis.com/maps/api/place/details/json?placeid=<?php echo $placeId ?>&key=<?php echo $api_key ?>', function(data) {
$.each(data.reviews, function(i, f) {
var tblRow = "<tr>" + "<td>" + f.author_name + "</td>" +
"<td>" + f.rating + "</td>" + "<td>" + f.relative_time_description + "</td>" + "<td>" + f.text + "</td>" + "</tr>"
$(tblRow).appendTo("#google-reviews");
});
});
});
</script>
I'm looking to receive a response similar to this json file:
{
"html_attributions" : [],
"result" : {
...
"rating" : 4.5,
"reference" : "CmRSAAAAjiEr2_A4yI-DyqGcfsceTv-IBJXHB5-W3ckmGk9QAYk4USgeV8ihBcGBEK5Z1w4ajRZNVAfSbROiKbbuniq0c9rIq_xqkrf_3HpZzX-pFJuJY3cBtG68LSAHzWXB8UzwEhAx04rgN0_WieYLfVp4K0duGhTU58LFaqwcaex73Kcyy0ghYOQTkg",
"reviews" : [
{
"author_name" : "Robert Ardill",
"author_url" : "https://www.google.com/maps/contrib/106422854611155436041/reviews",
"language" : "en",
"profile_photo_url" : "https://lh3.googleusercontent.com/-T47KxWuAoJU/AAAAAAAAAAI/AAAAAAAAAZo/BDmyI12BZAs/s128-c0x00000000-cc-rp-mo-ba1/photo.jpg",
"rating" : 5,
"relative_time_description" : "a month ago",
"text" : "Awesome offices. Great facilities, location and views. Staff are great hosts",
"time" : 1491144016
}
],
"types" : [ "point_of_interest", "establishment" ],
"url" : "https://maps.google.com/?cid=10281119596374313554",
"utc_offset" : 600,
"vicinity" : "5, 48 Pirrama Road, Pyrmont",
"website" : "https://www.google.com.au/about/careers/locations/sydney/"
},
"status" : "OK"
}
However, I keep encountering two errors:
https://maps.googleapis.com/maps/api/place/details/json?placeid={placeid}&key={apikey} net::ERR_FAILED
Access to XMLHttpRequest at 'https://maps.googleapis.com/maps/api/place/details/json?placeid={placeid}&key={apikey}' from origin '{the site I work on}' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Anyone have a solution for this issue?