djangogoogle-places-apigoogle-cloud-consolegoogle-reviews

How to Embed google review in Django website?


I was going through the Google Cloud Platform Console to find out how I could embed a Google review on my Django website. I found the Google Places API to be the most relevant (not quite sure), but then I got lost with all the details, pricing, and different tiers. My case is actually quite simple. I just want to display the total number of stars a specific place has. Is there a free way to get that, which I didn't understand?


Solution

  • Through the Google Places API, you can indeed display the average number of stars for a specific place on your website using the rating field. However, it's important to remember that you must display the Google logo and other appropriate attributions according to the Places API Terms of Service.

    The Google Places API operates on a pay-as-you-go pricing model, meaning you will be charged based on the number of requests you make.

    Specifically, fetching details about a place including its rating, counts as a Place Details request, which is charged for $0.017 per call as stated on its Usage and Billing documentation.

    A Place Details call or request also generates Data SKUs (Basic, Contact, and/or Atmosphere), depending on the fields that are specified in the call or request. If NO fields are specified in the Place Details call or request, ALL Data SKUs are triggered, and you are charged for the Places Details call or request plus the cost of all the data.

    The rating field falls under the Atmosphere category and is charged for $0.005 per request.

    That said, retrieving the average rating of a specific place using Places API will cost you:

    $0.017 (Place Details request) + $0.005 (Atmosphere Data SKU) = $0.022 per request.

    To show that the Places API can return averaged star ratings, using the googlemaps library, below is a request sent through CodeSandbox that retrieves the rating of a coffee shop using its Place ID.

    from googlemaps import Client
    api_key = "YOUR_API_KEY"
    place_id = "ChIJoZqnday3lzMR9WJ8w09DCn0"
    
    client = Client(api_key)
    fields = ["rating"]
    try:
        place_details = client.place(place_id=place_id, fields=fields)
        average_rating = place_details["result"]["rating"]
        print(f"Average rating: {average_rating}")
    except googlemaps.exceptions.ApiError as e:
        print(f"Google Maps API error: {e}")
    except Exception as e:
        print(f"Unexpected error occurred: {e}")
    

    Result:

    Average rating: 4.3