簡體   English   中英

API 獲得 Google 的所有評論和評級

[英]API to get all the reviews and rating from Google for business

我正在使用谷歌地圖 API 來獲取公司的評論和評級。

步驟一:HTTP 請求獲取參考Id。

$url = 'https://maps.googleapis.com/maps/api/place/textsearch/json?query='.<CompanyName>.'&sensor=true&key='.<apikey>;

在 HTTP 請求之后,我得到了業務的參考 ID。

第 2 步:HTTP 請求獲取評論。

$url = 'https://maps.googleapis.com/maps/api/place/details/json?reference='.<referenceId>.'&key='.<apiKey>

有了以上內容,我得到了“最有幫助的評論”和最多 5 條評論。

所以我想獲得所有評論或最新評論。 我需要添加參數嗎?

如果您想獲得所有評論,您應該需要使用 Google My Business API。

這是另一個不同的 API,您應該向 Google 請求該地點的財產。

https://developers.google.com/my-business/content/review-data#list_all_reviews

使用位置的 place_id 獲取最后 5 次回訪的其他簡單方法(您可以在此處找到它: https : //developers.google.com/places/place-id

$url = "https://maps.googleapis.com/maps/api/place/details/json?key=Yourkey&placeid=YourplaceID";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec ($ch);
$res        = json_decode($result,true);
$reviews    = $res['result']['reviews'];

目前,Google 最多只提供五個結果,他們在文檔中提到了這一點。 如果您想獲得有關您自己的財產/地點或業務的評論,您可以選擇我的業務,​​但我認為他們使該 API 關閉了。

編輯:如果您仍然想獲取所有評論,您可以使用 HTML 解析器並解析所有評論(我不了解 Google 的數據政策,但您絕對可以從網站上抓取所有內容)

有像 SerpApi 這樣的第三方解決方案,您可以使用它來獲取任何地方的所有評論。 這是一個免費試用的付費 API。

每頁有 10 個結果。 要實現分頁,只需使用定義結果偏移量的start參數(例如, 0 (默認)是結果的第一頁, 10是結果的第二頁, 20是結果的第三頁,等等)

require 'path/to/google_search_results';

$query = [
  "engine" => "google_maps_reviews",
  "place_id" => "0x89c259a61c75684f:0x79d31adb123348d2",
  "api_key" => "SECRET_API_KEY"
];

$search = new GoogleSearch();
$results = $search->json($query);
$reviews = $result->reviews;

示例輸出:

"reviews": [
  {
    "user": {
      "name": "Waylon Bilbrey",
      "link": "https://www.google.com/maps/contrib/107691056156160235121?hl=en-US&sa=X&ved=2ahUKEwiUituIlpTvAhVYCc0KHbvTCrgQvvQBegQIARAx",
      "thumbnail": "https://lh3.googleusercontent.com/a-/AOh14GjOj6Wjfk1kSYjhvH7WIBNMdl4nPj6FvUhvYcR6=s40-c0x00000000-cc-rp",
      "reviews": 1
    },
    "rating": 4,
    "date": "a week ago",
    "snippet": "I've been here multiple times. The coffee itself is just average to me. The service is good (the people working are nice). The aesthetic is obviously what brings the place some fame. A little overpriced (even for NY). A very small cup for $6 where I feel like the price comes from the top rainbow foam decor , when I'm going to cover it anyways. If it's for an insta pic then it may be worth it?"
  },
  {
    "user": {
      "name": "Amber Grace Sale",
      "link": "https://www.google.com/maps/contrib/106390058588469541899?hl=en-US&sa=X&ved=2ahUKEwiUituIlpTvAhVYCc0KHbvTCrgQvvQBegQIARA7",
      "thumbnail": "https://lh3.googleusercontent.com/a-/AOh14Gj84nHu_9V_0V4yRbZcr-8ZTYAHua6gUBP8fC7W=s40-c0x00000000-cc-rp-ba3",
      "local_guide": true,
      "reviews": 33,
      "photos": 17
    },
    "rating": 5,
    "date": "2 years ago",
    "snippet": "They really take pride in their espresso roast here and the staff is extremely knowledgeable on the subject. It’s also a GREAT place to do work although a table is no guarantee; you might have to wait for a bit. My almond milk cappuccino was very acidic at the end which wasn’t expected but I could still tell the bean was high quality. Their larger lattés they put in a tall glass cup which looks really really cool. Would definitely go again.",
    "likes": 2,
    "images": [
      "https://lh5.googleusercontent.com/p/AF1QipMup24_dHrWtNN4ZD70EPsiRMf_tykcUkPw6A1H=w100-h100-p-n-k-no"
    ]
  },
  {
    "user": {
      "name": "Kelvin Petar",
      "link": "https://www.google.com/maps/contrib/100859090874785206875?hl=en-US&sa=X&ved=2ahUKEwiUituIlpTvAhVYCc0KHbvTCrgQvvQBegQIARBG",
      "thumbnail": "https://lh3.googleusercontent.com/a-/AOh14GhdIvUDamzfPqbYIpwhnGJV2XWSi77iVXfEsiKS=s40-c0x00000000-cc-rp",
      "reviews": 3
    },
    "rating": 4,
    "date": "3 months ago",
    "snippet": "Stumptown Cafe is the perfect place to work or catch up with friends. Never too loud, never too dead. Their lattes and deliciously addicting and the toasts are tasty as well. Wifi is always fast, which is a huge plus! The staff are the friendliest, I highly recommend this place!"
  },
  ...
]

您可以查看文檔以獲取更多詳細信息。

免責聲明:我在 SerpApi 工作。

正如 jNambiar 正確指出的那樣,Google 目前已將最大結果限制為 5。您將不得不使用一些 3rd 方解決方案,例如APIPedia.io ,它們提供多達 200 個左右的評論結果。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM