במדריך הזה מוסבר איך להציג, להחזיר, למחוק ביקורת ולהשיב עליה. Google My Business API מאפשר לכם לעבוד עם נתוני הביקורות כדי לבצע את הפעולות הבאות:
- הצגת רשימה של כל הביקורות.
- קבלת ביקורת ספציפית.
- לקבל ביקורות מכמה מיקומים.
- להגיב לביקורת.
- מחיקת תשובה לביקורת.
לפני שמתחילים
לפני שמשתמשים ב-Google My Business API, צריך לרשום את האפליקציה ולקבל פרטי כניסה ל-OAuth 2.0. במאמר הגדרה בסיסית מוסבר איך מתחילים לעבוד עם Google My Business 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; }
נתונים נוספים
ספריית הלקוח של Java מאפשרת לכם לגשת לנתוני שדות נוספים של מופעי ביקורת. אפשר להשתמש בשיטות הבאות כדי להחזיר נתונים נוספים על ביקורות:
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; }