Menggunakan data ulasan

Tutorial ini menunjukkan kepada Anda cara melihat daftar ulasan serta menampilkan, membalas, dan menghapus ulasan. Google My Business API memberi Anda kemampuan menggunakan data ulasan untuk melakukan operasi berikut:

Sebelum memulai

Sebelum menggunakan Google My Business API, Anda harus mendaftarkan aplikasi Anda dan mendapatkan kredensial OAuth 2.0. Untuk mendapatkan detail tentang cara memulai Google My Business API, lihat Penyiapan dasar.

Melihat daftar semua ulasan

Lihat daftar semua ulasan lokasi untuk mengaudit ulasan dalam jumlah besar. Gunakan accounts.locations.reviews.list API untuk menampilkan semua ulasan yang terkait dengan lokasi.

Untuk menampilkan semua ulasan yang terkait dengan lokasi, gunakan hal berikut:

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

Fungsi berikut menggunakan 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;
}

Mendapatkan ulasan spesifik

Tampilkan ulasan spesifik menurut nama. Gunakan accounts.locations.reviews.get API untuk menampilkan ulasan spesifik yang terkait dengan lokasi.

Untuk menampilkan ulasan spesifik, gunakan hal berikut:

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

Fungsi berikut menggunakan 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;
}

Data tambahan

Library Klien Java memberi Anda akses ke data kolom tambahan untuk instance ulasan. Gunakan metode berikut untuk menampilkan data tambahan tentang ulasan:

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

Mendapatkan ulasan dari beberapa lokasi

Dapatkan ulasan dari beberapa lokasi. Gunakan accounts.locations.batchGetReviews API untuk menampilkan ulasan dari beberapa lokasi dalam satu permintaan.

Untuk menampilkan ulasan dari beberapa lokasi, gunakan hal berikut:

HTTP

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

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

Membalas ulasan

Balas ulasan spesifik, atau buat balasan baru jika tidak ada. Gunakan accounts.locations.reviews.updateReply API untuk membalas ulasan spesifik yang terkait dengan lokasi.

Untuk membalas ulasan spesifik, gunakan hal berikut:

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

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

Fungsi berikut menggunakan 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;
}

Menghapus balasan ulasan

Menghapus balasan ulasan spesifik. Gunakan accounts.locations.reviews.deleteReply API untuk menghapus balasan ulasan spesifik yang terkait dengan lokasi.

Untuk menghapus balasan spesifik, gunakan hal berikut:

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

Fungsi berikut menggunakan 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;
}