במדריך הזה מוסבר איך להוסיף ביקורת, להחזיר אותה, להשיב עליה ולמחוק אותה. באמצעות ה-API של 'Google לעסק שלי' אפשר לעבוד עם נתוני בדיקה כדי לבצע את הפעולות הבאות:
- פירוט כל הביקורות.
- קבלת ביקורת ספציפית.
- קבלת ביקורות מכמה מיקומים.
- כתיבת תגובה לביקורת.
- מחיקת תגובה לביקורת.
לפני שמתחילים
לפני שתוכלו להשתמש ב-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 = accountsList.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 = reviewReply.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; }