Get reviews from google map api

前端 未结 4 1477
名媛妹妹
名媛妹妹 2020-12-13 05:06

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

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

the detai

4条回答
  •  一整个雨季
    2020-12-13 05:45

    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/

提交回复
热议问题