리뷰 데이터 사용

이 가이드에서는 리뷰의 목록 생성, 반환, 답글 달기, 삭제 방법을 보여줍니다. 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;
}

추가 데이터

자바 클라이언트 라이브러리를 사용하면 리뷰 인스턴스의 추가 필드 데이터에 액세스할 수 있습니다. 다음 메서드를 사용하여 리뷰에 관한 추가 데이터를 반환합니다.

  • 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;
}