27

I have to get reviews from Google map API. details are on this page.

https://developers.google.com/places/documentation/details#PlaceDetailsResults

the details will fetch from this page:-

https://maps.googleapis.com/maps/api/place/details/json?reference=CmRYAAAAciqGsTRX1mXRvuXSH2ErwW-jCINE1aLiwP64MCWDN5vkXvXoQGPKldMfmdGyqWSpm7BEYCgDm-iv7Kc2PF7QA7brMAwBbAcqMr5i1f4PwTpaovIZjysCEZTry8Ez30wpEhCNCXpynextCld2EBsDkRKsGhSLayuRyFsex6JA6NPh9dyupoTH3g&sensor=true&key=AddYourOwnKeyHere

My problem is I can't find what is reference in request. and how I find this parameter value from my Google plus page.

Kara
  • 6,115
  • 16
  • 50
  • 57
Himanshu Pandey
  • 1,250
  • 2
  • 23
  • 38

5 Answers5

41

A more recent way to do this:

https://maps.googleapis.com/maps/api/place/details/json?placeid={place_id}&key={api_key}

Response:

{
  "html_attributions": [],
  "result": {
    ...
    "rating": 4.6,
    "reviews": [
      {
        "author_name": "John Smith",
        "author_url": "https://www.google.com/maps/contrib/106615704148318066456/reviews",
        "language": "en",
        "profile_photo_url": "https://lh4.googleusercontent.com/-2t1b0vo3t-Y/AAAAAAAAAAI/AAAAAAAAAHA/0TUB0z30s-U/s150-c0x00000000-cc-rp-mo/photo.jpg",
        "rating": 5,
        "relative_time_description": "in the last week",
        "text": "Great time! 5 stars!",
        "time": 1508340655
      }
    ]
  }
}

Reviews are limited to the 5 latest.

JM-AGMS
  • 1,670
  • 1
  • 15
  • 33
  • 2
    thanks, the old method mentioned from @abbas udin din't wor, but this returns the reviews. – Wang'l Pakhrin Jun 11 '18 at 01:39
  • I am getting below error:Access to XMLHttpRequest at 'https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJkQYP8U6EXjkRShBlLAg2uqs&key=apikey' from origin 'https://saifkart.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource – user1881820 Apr 24 '19 at 04:51
  • 1
    This works but only for the last 5 reviews, to get more reviews I had to use an external service called wextractor.com – Pesto D Sep 29 '19 at 19:42
  • 3
    It returns 5 reviews not the 5 latest reviews! – pseudozach Nov 11 '19 at 18:15
  • Do you know of a way to get the reviews for a user, across multiple places? Using user api maybe? – Craig Lambie Jan 01 '21 at 12:23
  • And how do you make it work for localhost? Using Laragon I'm have example.com.test site that points to 127.0.0.1 through hosts. Then `$url = "https://maps.googleapis.com/maps/api/place/details/json?placeid={$place_id}&key={$key}"; $result = json_decode(file_get_contents($url), true);` returns `array ( 'error_message' => 'This API project is not authorized to use this API.', 'html_attributions' => array ( ), 'status' => 'REQUEST_DENIED', )` – s3c Feb 18 '21 at 14:27
5

For fetching a google review you need reference id for the place.In order to get this reference key you can use google places search api request.

https://maps.googleapis.com/maps/api/place/textsearch/xml?query=restaurants+in+bangalore&sensor=true&key=AddYourOwnKeyHere

Its response will have reference id which you can use in your request.

    <PlaceSearchResponse>
    <status>OK</status>
    <result>
    <name>Koshy's Restaurant</name>
    <type>bar</type>
    <type>restaurant</type>
    <type>food</type>
    <type>establishment</type>
    <formatted_address>
    39, St Marks Road,Shivajinagar,Bangalore, Karnataka, 560001, India
    </formatted_address>
    <geometry>
    <rating>3.7</rating>
    <icon>
    http://maps.gstatic.com/mapfiles/place_api/icons/bar-71.png
    </icon>
    **<reference>**
    CnRwAAAA1z8aCeII_F2wIVcCnDVPQHQi5zdd-3FsDl6Xhb_16OGrILvvvI4X4M8bFk2U8YvuDCKcFBn_a2rjvYDtvUZJrHykDAntE48L5UX9hUy71Z4n80cO7ve_JXww6zUkoisfFnu6jEHcnKeeTUE42PCA4BIQGhGz0VrXWbADarhKwCQnKhoUOR-Xa9R6Skl0TZmOI4seqt8rO8I
    **</reference>**
    <id>2730db556ca6707ef517e5c165adda05d2395b90</id>
    <opening_hours>
    <open_now>true</open_now>
    </opening_hours>
    <html_attribution>
    <a href="https://plus.google.com/116912222767108657277">Ujaval Gandhi</a>
    </html_attribution>
    </photo>
    </result>
Amit Singh
  • 149
  • 1
  • 6
3
$reqUri = 'https://maps.googleapis.com/maps/api/place/nearbysearch/json?key='.YOURSERVERKEY;
$reqUri .= '&sensor=false&radius=500';
$reqUri .= '&location=38.908310,-104.784035&name='.urlencode(LOCATION NAME);
$reqUri .= '&keyword='.urlencode(WEBSITE PHONE);

I made it through PHP, Now call like this URL and you get original result with reference key.

Then parse it like:

$data = cURL($reqUri);
$data = json_decode($data);
echo $data ->results[0]->reference;

Hope it will help you

***Note: location=38.908310,-104.784035 this var is not auto you must have it.

Abbas Uddin
  • 181
  • 1
  • 6
  • Up to 5 according to documentation: `* reviews[] a JSON array of up to five reviews. If a language parameter was specified in the Place Details request, the Places Service will bias the results to prefer reviews written in that language.` – SHG Mar 25 '17 at 03:46
  • i tried your api call, but it does not return any json with reviews. – Wang'l Pakhrin Jun 11 '18 at 01:35
1

Using Python and Google Places APIs, you can retrieve business details and reviews (up to 5 reviews) as follows:

api = GooglePlaces("Your API key")

places = api.search_places_by_coordinate("40.819057,-73.914048", "100", "restaurant")

for place in places:
    details = api.get_place_setails(place['place_id'], fields)
    try:
        website = details['result']['website']
    except KeyError:
        website = ""

    try:
        name = details['result']['name']
    except KeyError:
        name = ""

    try:
        address = details['result']['formatted_address']
    except KeyError:
        address = ""

    try:
        phone_number = details['result']['international_phone_number']
    except KeyError:
        phone_number = ""

    try:
        reviews = details['result']['reviews']
    except KeyError:
        reviews = []
    print("===================PLACE===================")
    print("Name:", name)
    print("Website:", website)
    print("Address:", address)
    print("Phone Number", phone_number)
    print("==================REVIEWS==================")
    for review in reviews:
        author_name = review['author_name']
        rating = review['rating']
        text = review['text']
        time = review['relative_time_description']
        profile_photo = review['profile_photo_url']
        print("Author Name:", author_name)
        print("Rating:", rating)
        print("Text:", text)
        print("Time:", time)
        print("Profile photo:", profile_photo)
        print("-----------------------------------------")

For more details about this code and Google Places API, you can check this tutorial: https://python.gotrained.com/google-places-api-extracting-location-data-reviews/

GoTrained
  • 158
  • 1
  • 7
  • Hi, is there a way to get more than 5 reviews (even if I pay)? i've enabled billing but can't seem to find out how to do this... might have to resort to Selenium .. :-) – tezzaaa Apr 15 '19 at 21:56
  • @tezzaaa The payment option seems to be related to number of requests (not reviews) https://developers.google.com/places/web-service/usage-and-billing So apparently the direct answer to your question is "no" - check the answers here as well: https://stackoverflow.com/questions/39223719/to-get-more-than-5-reviews-from-google-places-api – GoTrained Apr 17 '19 at 09:16
0

I had problems making it work on localhost. I added my example.com.test domain, but of course I could not verify it, because it cannot be reached from outside (except ngrok variant).

I found an amazing dirty hack on GitHub: gaffling/PHP-Grab-Google-Reviews.

Worked great for me, except I had to change the /* CHECK SORT */ line to if (isset($option['sort_by_reating_best_1']) and $option['sort_by_reating_best_1'] == true) and I also limited the foreach to only 5 reviews via optional second function parameter.

No API_KEY required at all

s3c
  • 1,481
  • 19
  • 28