【问题标题】:Get reviews from google map api从 google map api 获取评论
【发布时间】:2013-05-01 05:12:06
【问题描述】:

【问题讨论】:

    标签: google-maps google-plus


    【解决方案1】:

    要获取 google 评论,您需要该地点的参考 ID。为了获取此参考密钥,您可以使用 google places search api 请求。

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

    它的响应将包含您可以在请求中使用的参考 ID。

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

    【讨论】:

      【解决方案2】:
      $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);
      

      我是通过 PHP 实现的,现在像这个 URL 一样调用,你会得到带有引用键的原始结果。

      然后像这样解析它:

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

      希望对你有帮助

      ***注意:location=38.908310,-104.784035 这个变量不是自动的,你必须拥有它。

      【讨论】:

      • 根据文档最多 5 个:* 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.
      • 我试过你的 api 调用,但它没有返回任何带有评论的 json。
      【解决方案3】:

      一种更新的方法:

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

      回复:

      {
        "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
            }
          ]
        }
      }
      

      评论仅限于最新的 5 条。

      【讨论】:

      • 谢谢,@abbas udin 提到的旧方法不起作用,但这会返回评论。
      • 我遇到以下错误:从源 'saifkart.com' 访问 XMLHttpRequest 在 'maps.googleapis.com/maps/api/place/details/…' 已被 CORS 策略阻止:不存在 'Access-Control-Allow-Origin' 标头在请求的资源上
      • 这有效,但仅适用于最后 5 条评论,为了获得更多评论,我不得不使用名为 wextractor.com 的外部服务
      • 返回 5 条评论而不是 5 条最新评论!
      • 您知道一种跨多个地方获取用户评论的方法吗?也许使用用户 api?
      【解决方案4】:

      使用 Python 和 Google Places API,您可以检索业务详细信息和评论(最多 5 条评论),如下所示:

      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("-----------------------------------------")
      

      有关此代码和 Google Places API 的更多详细信息,您可以查看此教程:https://python.gotrained.com/google-places-api-extracting-location-data-reviews/

      【讨论】:

      • 嗨,有没有办法获得超过 5 条评论(即使我付费)?我已经启用了计费,但似乎无法找到如何做到这一点......可能不得不求助于 Selenium .. :-)
      • @tezzaaa 付款选项似乎与请求数量(不是评论)有关developers.google.com/places/web-service/usage-and-billing 所以显然您的问题的直接答案是“否” - 也可以在这里查看答案:@987654323 @
      【解决方案5】:

      我在 localhost 上运行时遇到了问题。我添加了我的 example.com.test 域,但我当然无法验证它,因为无法从外部访问它(ngrok 变体除外)。

      我在 GitHub 上发现了一个惊人的肮脏黑客:gaffling/PHP-Grab-Google-Reviews

      对我来说效果很好,除了我必须将 /* CHECK SORT */ 行更改为 if (isset($option['sort_by_reating_best_1']) and $option['sort_by_reating_best_1'] == true) 并且我还通过可选的第二个函数参数将 foreach 限制为仅 5 条评论。

      根本不需要 API_KEY

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-01-09
        • 2018-07-17
        • 2016-03-21
        • 2015-02-27
        • 2013-10-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多