Bu eğitimde, bir yorumu nasıl listeleyeceğiniz, geri vereceğiniz, yanıtlayacağınız ve sileceğiniz gösterilmektedir. Google Benim İşletmem API'si, aşağıdaki işlemleri gerçekleştirmek için yorum verileriyle çalışma olanağı sunar:
- Tüm yorumları listeleyin.
- Belirli bir yorum alın.
- Birden fazla konumdan yorum alın.
- Yorumları yanıtlayın.
- Bir yorum yanıtını silin.
Başlamadan önce
Google Benim İşletmem API'sini kullanmadan önce uygulamanızı kaydettirmeniz ve OAuth 2.0 kimlik bilgilerini almanız gerekir. Google Benim İşletmem API'sini kullanmaya başlama hakkında ayrıntılı bilgi için Temel kurulum başlıklı makaleyi inceleyin.
Tüm yorumları listele
Yorumları toplu olarak denetlemek için bir konumla ilgili tüm yorumları listeleyin. Bir konumla ilişkili tüm yorumları döndürmek için accounts.locations.reviews.list API'sini kullanın.
Bir konumla ilişkilendirilmiş tüm yorumları döndürmek için şunu kullanın:
GET https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/reviews
Aşağıdaki işlevde Mybusiness.Accounts.Locations.Reviews.List
kullanılmıştır.
/** * 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; }
Belirli bir yorumu alma
Belirli bir yorumu ada göre döndürün. Bir konumla ilişkili belirli bir yorumu döndürmek için accounts.locations.reviews.get API'sini kullanın.
Belirli bir yorumu geri vermek için aşağıdakileri kullanın:
GET https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/reviews/{reviewId}
Aşağıdaki işlevde Mybusiness.Accounts.Locations.Reviews.Get
kullanılmıştır.
/** * 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; }
Ek veriler
Java İstemci Kitaplığı, inceleme örnekleri için ek alan verilerine erişmenizi sağlar. Yorumlarla ilgili ek veri döndürmek için aşağıdaki yöntemleri kullanın:
getReviewId()
getComment()
getReviewer()
getStarRating()
getCreateTime()
getReviewReply()
Birden fazla konumdan yorum alma
Birden fazla yerden yorum alın. Tek bir istekte birden fazla konumdaki yorumları döndürmek için accounts.locations.batchGetReviews API'sini kullanın.
Birden fazla konumdaki yorumları döndürmek için aşağıdakileri kullanın:
POST https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations:batchGetReviews { "locationNames": [ string ], "pageSize": number, "pageToken": string, "orderBy": string, "ignoreRatingOnlyReviews": boolean }
Yorumları yanıtlama
Belirli bir yorum için yanıt verin veya mevcut bir yanıt yoksa yeni bir yanıt oluşturun. Bir konumla ilişkili belirli bir yorumu yanıtlamak için accounts.locations.reviews.updateReply API'sini kullanın.
Belirli bir yorumu yanıtlamak için aşağıdakileri kullanın:
PUT https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/reviews/{reviewId}/reply { comment: "Thank you for visiting our business!" }
Aşağıdaki işlevde Mybusiness.accounts.locations.reviews.reply
kullanılmıştır.
/* * 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; }
Yorum yanıtlarını silme
Belirli bir yoruma verilen yanıtı silme. Bir konumla ilişkili belirli bir yoruma verilen yanıtı silmek için accounts.locations.reviews.deleteReply API'sini kullanın.
Bir yoruma verilen belirli bir yanıtı silmek için aşağıdakileri kullanın:
DELETE https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/reviews/{reviewId}/reply
Aşağıdaki işlevde Mybusiness.Accounts.Locations.Reviews.DeleteReply
kullanılmıştır.
/** * 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; }