As we know Google Reviews are considered as one of the most authenticated tools which have a direct impact on your brand identity. Today we have taken the initiative to educate you on how you can request Google to display your business reviews on your site with help of listed address and an API Key.
Some prerequisite requirements before we proceed are.
- Your brand name and address should be registered or listed with Google.
- An API Key from Google Places App
To generate the API Key Follow the below steps.
- Proceed to https://developers.google.com/places/web-service/get-api-key ab=nd log in with your Gmail ID.
- Click on Get A Key button just below the search bar.
- Select from the existing project if you have or Create the new project.
- Enter a user-friendly name for your project and click on “Create and Enable API”.
- Your Project will be created and API Key will be displayed simply copy the key and keep it safe for upcoming use.
Now let us start in order to extract the reviews we need to follow 2 steps
- Get the Place ID from the address.
- Use the Place ID to extract the reviews.
So let’s start towards achieving our 1st goal i.e to get the Place ID of the location.
Create a file google_reviews.php
First, we will request Google for all relevant details for the given location including its Place ID.
Note Google does not excepts ant space between the Address or Name so firstly remove spaces between the words using str_replace
$address=str_replace(' ','','Your Address or Name registered with Google'); //To Remove the spaces between Name or Address.
$address2=str_replace(' ','','City Name'); // To Remove Spaces between city/state/country
$results = file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address='.$address.'&component='.$citystate.'"'); // Request Location Details from Google API's
$a=json_decode($results,true); //Get the result and dcode in Array Format
Now We will get all details for the Address Specified Like Latitute,Longitute,Google Map URL,Place ID etc
We will use the Place ID and get the reviews from the Google.
Here we Go
$plid=$a['results']['place_id']; // Assigning the Place ID in a Variable
//If Place ID is not null the go for Google Reviews
//Request the reviews by putting the Place ID and YOUR API KEY at the appropriate Locations.
$results1= file_get_contents('https://maps.googleapis.com/maps/api/place/details/json?placeid='.$plid.'&key='YOUR API KEY'');
//Decode the JSON Results into array format
//Count the Total Reviews
//IF Reviews exist then iterate over it
//LIST OF PARAMETERS YOU NEED TO PRINT IN YOUR HTML
$a1['result']['reviews'][$j]['profile_photo_url']; //For Reviewers Image
$a1['result']['reviews'][$j]['author_name']; //For Reviewers Name
$a1['result']['reviews'][$j]['relative_time_description'] ; //For Review Relative Timmings
$a1['result']['reviews'][$j]['rating']; //For Rating Given by Reviewer
$a1['result']['reviews'][$j]['text']; //For Review Text
So this is how we can extract the Google Page Reviews and display it on our website. Moreover this API is also helpful in getting Dynamic GOOGLE Maps URL which can be embedded in an IFRAME to display the maps at your own will.
Get Free working demo for above API Download Here.
You can also view our other trending topics
Because we believe Hurdles aren’t really Hurdles