با داده های بررسی کار کنید

این آموزش به شما نشان می‌دهد که چگونه یک نظر را فهرست کنید، برگردانید، پاسخ دهید و حذف کنید. API گوگل مای بیزینس به شما این امکان را می‌دهد که با داده‌های نظر کار کنید تا عملیات زیر را انجام دهید:

قبل از اینکه شروع کنی

قبل از استفاده از API گوگل مای بیزینس، باید برنامه خود را ثبت کنید و اعتبارنامه‌های OAuth 2.0 را دریافت کنید. برای جزئیات بیشتر در مورد نحوه شروع به کار با API گوگل مای بیزینس، به تنظیمات اولیه مراجعه کنید.

فهرست کردن همه نقدها

تمام نظرات مربوط به یک مکان را برای حسابرسی کلی فهرست کنید. از API accounts.locations.reviews.list برای بازگرداندن تمام نظرات مرتبط با یک مکان استفاده کنید.

برای نمایش تمام نظرات مرتبط با یک مکان، از موارد زیر استفاده کنید:

اچ‌تی‌پی
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 = reviewsList.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;
}

داده‌های اضافی

کتابخانه کلاینت جاوا به شما امکان دسترسی به داده‌های فیلد اضافی برای نمونه‌های بررسی را می‌دهد. از روش‌های زیر برای بازگرداندن داده‌های اضافی در مورد بررسی‌ها استفاده کنید:

  • 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  = reply.execute();

  return response;
}

حذف پاسخ بررسی

حذف پاسخ به یک نظر خاص. از API accounts.locations.reviews.deleteReply برای حذف پاسخ به یک نظر خاص مرتبط با یک مکان استفاده کنید.

برای حذف یک پاسخ خاص به یک نظر، از موارد زیر استفاده کنید:

اچ‌تی‌پی
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;
}