บทแนะนำนี้จะแสดงวิธีแสดง แสดงผลตอบแทน ตอบกลับ และลบรีวิว Google My Business API ช่วยให้คุณทำงานกับข้อมูลรีวิวเพื่อดำเนินการต่อไปนี้ได้
ก่อนเริ่มต้น
ก่อนใช้ Google My Business API คุณต้องลงทะเบียนแอปพลิเคชันและรับข้อมูลเข้าสู่ระบบ OAuth 2.0 ดูรายละเอียดเกี่ยวกับวิธีเริ่มต้นใช้งาน Google My Business API ได้ที่การตั้งค่าพื้นฐาน
แสดงรีวิวทั้งหมด
แสดงรีวิวทั้งหมดของสถานที่หนึ่งเพื่อตรวจสอบรีวิวแบบเป็นกลุ่ม ใช้ accounts.locations.reviews.list API เพื่อแสดงรีวิวทั้งหมดที่เชื่อมโยงกับสถานที่ตั้ง
หากต้องการแสดงรีวิวทั้งหมดที่เชื่อมโยงกับสถานที่ ให้ใช้คำสั่งต่อไปนี้
GET https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/reviews
ฟังก์ชันต่อไปนี้ใช้ 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; }
ดูรีวิวที่เฉพาะเจาะจง
แสดงรีวิวที่เฉพาะเจาะจงตามชื่อ ใช้ API accounts.locations.reviews.get เพื่อแสดงรีวิวที่เชื่อมโยงกับสถานที่หนึ่งๆ
หากต้องการแสดงรีวิวที่เฉพาะเจาะจง ให้ใช้คำสั่งต่อไปนี้
GET https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/reviews/{reviewId}
ฟังก์ชันต่อไปนี้ใช้ 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()
ดูรีวิวจากหลายตำแหน่ง
ดูรีวิวจากหลายสถานที่ ใช้ API accounts.locations.batchGetReviews เพื่อแสดงรีวิวจากสถานที่หลายแห่งในคําขอเดียว
หากต้องการแสดงรีวิวจากหลายตำแหน่ง ให้ใช้คำสั่งต่อไปนี้
POST https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations:batchGetReviews { "locationNames": [ string ], "pageSize": number, "pageToken": string, "orderBy": string, "ignoreRatingOnlyReviews": boolean }
ตอบรีวิว
ตอบรีวิวที่เฉพาะเจาะจง หรือสร้างการตอบกลับใหม่หากยังไม่มี ใช้ API ของ accounts.locations.reviews.updateReply เพื่อตอบกลับรีวิวที่เชื่อมโยงกับสถานที่หนึ่งๆ
หากต้องการตอบกลับรีวิวที่เฉพาะเจาะจง ให้ใช้ข้อความต่อไปนี้
PUT https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/reviews/{reviewId}/reply { comment: "Thank you for visiting our business!" }
ฟังก์ชันต่อไปนี้ใช้ 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 เพื่อลบการตอบรีวิวที่เชื่อมโยงกับสถานที่หนึ่งๆ
หากต้องการลบการตอบรีวิวที่เฉพาะเจาะจง ให้ทำดังนี้
DELETE https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/reviews/{reviewId}/reply
ฟังก์ชันต่อไปนี้ใช้ 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; }