Get Google Reviews on Website based on Google Business Listing

No votes yet.
Please wait...

Hey Mates,

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.

  1. Your brand name and address should be registered or listed with Google.
  2. An API Key from Google Places App

To generate the API Key Follow the below steps.

  1. Proceed to https://developers.google.com/places/web-service/get-api-key ab=nd log in with your Gmail ID.
  2. Click on Get A Key button just below the search bar.
  3. Select from the existing project if you have or Create the new project.
  4. Enter a user-friendly name for your project and click on “Create and Enable API”.
  5. 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

1
2
3
4
5
6
7
8
9
10
<?php

$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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
$plid=$a['results'][0]['place_id'];   // Assigning the Place ID in a Variable

//If Place ID is not null the  go for Google Reviews
if($plid<>'')
{

//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

$a1=json_decode($results1,true);

//Count the Total Reviews

$qft=count($a1['result']['reviews']);

//IF Reviews exist then iterate over it

if($qft<>''){

for($j=0;$j<$qft;$j++)

{

//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

Display Facebook Page Reviews On Your Website
Compress Image Before Upload

Cheers!

Because we believe Hurdles aren’t really Hurdles

2 Comments

  1. mr j said:

    still this time i was using curl for all my apis, now i can save 7 sec wth file_get_contents , thanks for this awesome tutorial 🙂

    No votes yet.
    Please wait...
    July 21, 2017
    Reply
    • Saurabh Dubey said:

      Thank You Mate,

      We Love helping our developer

      Cheers!

      No votes yet.
      Please wait...
      July 22, 2017
      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Solve : *
18 × 29 =