עבודה עם נתוני ביקורות

במדריך הזה נסביר איך להציג ביקורת, להחזיר אותה, להשיב לה ולמחוק אותה. ה-API של 'Google לעסק שלי' מאפשר לכם לעבוד עם נתוני ביקורות כדי לבצע את הפעולות הבאות:

לפני שמתחילים

לפני שמשתמשים ב-API של 'Google לעסק שלי', צריך לרשום את האפליקציה ולקבל פרטי כניסה ל-OAuth 2.0. למידע נוסף על תחילת העבודה עם Google My Business API, קראו את המאמר הגדרה בסיסית.

הצגת רשימה של כל הביקורות

כדי לבדוק את הביקורות בכמות גדולה, אפשר להציג רשימה של כל הביקורות על מקום מסוים. אפשר להשתמש ב-API‏ accounts.locations.reviews.list כדי להציג את כל הביקורות שמשויכות למיקום מסוים.

כדי להציג את כל הביקורות שמשויכות למיקום מסוים, משתמשים בקוד הבא:

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

אחזור ביקורת ספציפית

הצגת ביקורת ספציפית לפי שם. אפשר להשתמש ב-API‏ accounts.locations.reviews.get כדי להציג ביקורת ספציפית שמשויכת למיקום.

כדי להציג ביקורת ספציפית, משתמשים בקוד הבא:

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

נתונים נוספים

ספריית הלקוח של Java מספקת גישה לנתוני שדות נוספים למקרים של בדיקה. כדי להציג נתונים נוספים על ביקורות, אפשר להשתמש בשיטות הבאות:

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

הצגת ביקורות ממספר מיקומים

לקבל ביקורות ממספר מיקומים. אפשר להשתמש ב-API‏ accounts.locations.batchGetReviews כדי להציג ביקורות ממספר מיקומים בבקשה אחת.

כדי להציג ביקורות מכמה מיקומים, צריך להשתמש בקוד הבא:

HTTP

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 כדי להשיב לביקורת ספציפית שמשויכת למיקום.

כדי להשיב לביקורת ספציפית, צריך להשתמש באפשרות הבאה:

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

מחיקת תשובה לביקורת

למחוק תשובה לביקורת ספציפית. אפשר להשתמש ב-API‏ accounts.locations.reviews.deleteReply כדי למחוק תשובה לביקורת ספציפית שמשויכת למיקום.

כדי למחוק תשובה ספציפית לביקורת, מבצעים את הפעולות הבאות:

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