کار کردن با داده‌های بازبینی

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

قبل‌از شروع

قبل‌از استفاده از 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
جاوا

تابع زیر از 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;
}

دریافت کردن مروری خاص

مرور خاصی را براساس نام برمی‌گرداند. از accounts.locations.reviews.get API برای برگرداندن مرور خاصی که با مکان مرتبط است استفاده کنید.

برای برگرداندن یک مرور خاص، از موارد زیر استفاده کنید:

HTTP
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()

دریافت مرور از چند مکان

مرورها را از چندین مکان دریافت کنید. از 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!"
}
جاوا

تابع زیر از 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;
}

حذف پاسخ مرور

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

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

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