Làm việc với dữ liệu đánh giá

Hướng dẫn này chỉ cho bạn cách liệt kê, trả lại, trả lời và xóa bài đánh giá. API Google Doanh nghiệp của tôi cho phép bạn làm việc với dữ liệu đánh giá để thực hiện các thao tác sau:

Trước khi bắt đầu

Trước khi sử dụng API Google Doanh nghiệp của tôi, bạn cần đăng ký ứng dụng của mình và lấy thông tin xác thực OAuth 2.0. Để biết thông tin chi tiết về cách bắt đầu sử dụng API Google Doanh nghiệp của tôi, hãy xem bài viết Thiết lập cơ bản.

Liệt kê tất cả bài đánh giá

Liệt kê tất cả bài đánh giá về một địa điểm để kiểm tra hàng loạt bài đánh giá. Hãy sử dụng API accounts.locations.reviews.list để trả về tất cả các bài đánh giá liên quan đến một địa điểm.

Để trả lại tất cả bài đánh giá liên quan đến một vị trí, hãy sử dụng các hàm sau:

HTTP
GET
https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/reviews
Java

Hàm sau sử dụng Mybusiness.Accounts.Locations.Reviews.List.

/**
 * Returns a list of reviews.
 * @param locationName Name of the location to retrieve reviews for.
 * @return List<Reviews> A list of reviews.
 * @throws Exception
 */
public static List<Review> listReviews(String locationName) throws Exception {
  Mybusiness.Accounts.Locations.Reviews.List reviewsList =
    mybusiness.accounts().locations().reviews().list(locationName);
  ListReviewsResponse response = accountsList.execute();
  List<Reviews> reviews = response.getReviews();

  for (Reviews review : reviews) {
    System.out.println(review.toPrettyString());
  }
  return reviews;
}

Xem bài đánh giá cụ thể

Trả lại bài đánh giá cụ thể theo tên. Hãy sử dụng API accounts.locations.reviews.get để trả về một bài đánh giá cụ thể liên quan đến một vị trí.

Để trả lại một bài đánh giá cụ thể, hãy dùng:

HTTP
GET
https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/reviews/{reviewId}
Java

Hàm sau sử dụng Mybusiness.Accounts.Locations.Reviews.Get.

/**
 * Demonstrates getting a review by name.
 * @param reviewName The name (resource path) of the review to retrieve.
 * @return Account The requested review.
 */
private static Review getReview(String reviewName) throws Exception {
  Mybusiness.Accounts.Locations.Reviews.Get review =
      mybusiness.accounts().locations().reviews().get(reviewName);
  Review response = review.execute();

  return response;
}

Dữ liệu bổ sung

Thư viện ứng dụng Java cho phép bạn truy cập vào dữ liệu bổ sung của trường cho các thực thể xem xét. Hãy sử dụng các phương thức sau để trả về dữ liệu bổ sung về các bài đánh giá:

  • getReviewId()
  • getComment()
  • getReviewer()
  • getStarRating()
  • getCreateTime()
  • getReviewReply()

Nhận bài đánh giá từ nhiều địa điểm

Nhận bài đánh giá từ nhiều địa điểm. Sử dụng API accounts.locations.batchGetReviews để trả về bài đánh giá từ nhiều vị trí trong một yêu cầu duy nhất.

Để trả lại bài đánh giá từ nhiều vị trí, hãy sử dụng:

HTTP

POST
https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations:batchGetReviews

{
  "locationNames": [
    string
  ],
  "pageSize": number,
  "pageToken": string,
  "orderBy": string,
  "ignoreRatingOnlyReviews": boolean
}

Trả lời bài đánh giá

Trả lời bài đánh giá cụ thể hoặc tạo câu trả lời mới nếu chưa có. Hãy sử dụng API accounts.locations.reviews.updateReply để trả lời các bài đánh giá cụ thể liên quan đến một địa điểm.

Để trả lời một bài đánh giá cụ thể, hãy dùng:

HTTP
PUT
https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/reviews/{reviewId}/reply

{
  comment: "Thank you for visiting our business!"
}
Java

Hàm sau sử dụng Mybusiness.accounts.locations.reviews.reply.


/*
 * Updates the reply for a location review.
 * If a review does not exist, creates a new one.
 * @param reviewName Name of the review being responded to.
 * @param comment A string containing the review response body.
 * @throws IOException
 */
private static Reply reply(String reviewName, String comment) throws IOException {

  MyBusiness.Accounts.Locations.Reviews.Reply reply =
    mybusiness().accounts().locations().reviews().reply(reviewName, comment);

  Reply response  = reviewReply.execute();

  return response;
}

Xoá câu trả lời cho bài đánh giá

Xoá nội dung trả lời cho một bài đánh giá cụ thể. Bạn có thể sử dụng API accounts.locations.reviews.deleteReply để xoá câu trả lời cho bài đánh giá cụ thể có liên quan đến một địa điểm.

Để xoá nội dung trả lời cụ thể cho bài đánh giá, hãy dùng các cách sau:

HTTP
DELETE
https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/reviews/{reviewId}/reply
Java

Hàm sau sử dụng Mybusiness.Accounts.Locations.Reviews.DeleteReply.

/**
 * Demonstrates deleting a review reply by name.
 * @param reviewName The name (resource path) of the review reply to delete.
 * @return Account The requested review.
 */
private static DeleteReply deleteReply(String reviewName) throws Exception {
  Mybusiness.Accounts.Locations.Reviews.DeleteReply toDelete =
      mybusiness.accounts().locations().reviews().deleteReply(reviewName);
  DeleteReply response = toDelete.execute();

  return response;
}