ทํางานกับข้อมูลรีวิว

บทแนะนำนี้จะแสดงวิธีแสดงรายการ ส่งคืน ตอบกลับ และลบรีวิว Google My Business API ช่วยให้คุณสามารถจัดการข้อมูลรีวิวเพื่อดำเนินการต่อไปนี้

ก่อนเริ่มต้น

ก่อนใช้ Google My Business API คุณต้องลงทะเบียนแอปพลิเคชันและรับข้อมูลเข้าสู่ระบบ OAuth 2.0 ดูรายละเอียดเกี่ยวกับวิธีเริ่มต้นใช้งาน Google My Business API ได้ที่การตั้งค่าพื้นฐาน

แสดงรายการรีวิวทั้งหมด

แสดงรายการรีวิวทั้งหมดของสถานที่เพื่อตรวจสอบรีวิวแบบเป็นกลุ่ม ใช้ accounts.locations.reviews.list API เพื่อแสดงผลรีวิวทั้งหมดที่เกี่ยวข้องกับสถานที่

หากต้องการแสดงรีวิวทั้งหมดที่เชื่อมโยงกับสถานที่ ให้ใช้การตั้งค่าต่อไปนี้

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

ฟังก์ชันต่อไปนี้ใช้ 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;
}

รับรีวิวที่เจาะจง

แสดงรีวิวที่เฉพาะเจาะจงตามชื่อ ใช้ accounts.locations.reviews.get API เพื่อส่งกลับรีวิวที่เจาะจงซึ่งเกี่ยวข้องกับสถานที่

หากต้องการส่งคืนรีวิวที่เจาะจง ให้ใช้การตั้งค่าต่อไปนี้

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

ฟังก์ชันต่อไปนี้ใช้ 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;
}

ข้อมูลเพิ่มเติม

ไลบรารีของไคลเอ็นต์ Java ให้คุณเข้าถึงช่องข้อมูลเพิ่มเติมสำหรับอินสแตนซ์การตรวจสอบ ใช้วิธีการต่อไปนี้เพื่อส่งข้อมูลเพิ่มเติมเกี่ยวกับรีวิว

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

รับรีวิวจากสถานที่หลายแห่ง

รับรีวิวจากสถานที่หลายแห่ง ใช้ accounts.locations.batchGetReviews API เพื่อแสดงผลรีวิวจากสถานที่หลายแห่งในคำขอเดียว

หากต้องการส่งคืนรีวิวจากสถานที่หลายแห่ง ให้ใช้การตั้งค่าต่อไปนี้

HTTP

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

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

ตอบรีวิว

ตอบรีวิวที่เฉพาะเจาะจง หรือสร้างการตอบกลับใหม่หากไม่มี ใช้ accounts.locations.reviews.updateReply API เพื่อตอบกลับรีวิวที่เฉพาะเจาะจงซึ่งเชื่อมโยงกับสถานที่

หากต้องการตอบกลับรีวิวรายการใดรายการหนึ่ง ให้ใช้การตั้งค่าต่อไปนี้

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

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

ฟังก์ชันต่อไปนี้ใช้ 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;
}

ลบการตอบรีวิว

ลบการตอบรีวิวที่เฉพาะเจาะจง ใช้ accounts.locations.reviews.deleteReply API เพื่อลบการตอบกลับของรีวิวที่เฉพาะเจาะจงซึ่งเชื่อมโยงกับสถานที่

หากต้องการลบการตอบรีวิวที่เฉพาะเจาะจง ให้ใช้วิธีต่อไปนี้

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

ฟังก์ชันต่อไปนี้ใช้ 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;
}