ביקורות על מוצרים הן חלק חשוב מחוויית הקנייה של הלקוחות. הדירוגים והביקורות האלה עוזרים ללקוחות לברר מידע על המוצרים ולקבל החלטות בנוגע לקנייה. ביקורות חיוביות על מוצרים יכולות למשוך יותר לקוחות מתאימים לדפי המוצרים של המוכר. המקורות כוללים מוכרים, אתרי אגרגטור שאוספים ביקורות, אתרי ביקורות ומשתמשים של Google.
בדף הזה נסביר איך לנהל ביקורות על מוצרים באמצעות Merchant API.
דרישות מוקדמות
Google זקוקה למידע ספציפי. נדרש לכם:
- פיד פעיל של ביקורות על מוצרים ב-Google Merchant Center.
- החשבון שלכם צריך להיות רשום בתוכנית דירוגי המוצרים. אם אתם לא בטוחים אם כבר נרשמתם, תוכלו לבדוק ב-Merchant Center. אם אתם לא רשומים לתוכנית, תוכלו לקרוא מידע נוסף על הרשמה לתוכנית דירוגי המוצרים.
- כדי לבדוק מוצרים באמצעות Merchant API, שולחים בקשה באמצעות הטופס הזה.
יצירת מקור נתונים
שימוש ב-datasource.create
API כדי ליצור פיד של ביקורות על מוצרים. אם יש פיד קיים של ביקורות על מוצרים, משתמשים ב-accounts.dataSources.get
כדי לאחזר את ה-accounts.dataSources.name
. טופס הבקשה הוא:
POST https://merchantapi.googleapis.com/datasources/v1beta/accounts/{account}/dataSources/{datasource}
דוגמה
בדוגמה מוצגות בקשה ותגובה אופייניות.
בקשה
POST https://merchantapi.googleapis.com/datasources/v1beta/accounts/123/dataSources {"displayName": "test api feed", "productReviewDataSource":{} }
תגובה
{
"name": "accounts/123/dataSources/1000000573361824",
"dataSourceId": "1000000573361824",
"displayName": "test api feed",
"productReviewDataSource": {},
"input": "API"
}
מידע נוסף זמין במאמר סקירה כללית על Merchant Data sources API.
יצירת ביקורת על מוצר
אפשר להשתמש ב-method accounts.productreviews.insert
כדי ליצור או לעדכן ביקורת על מוצר. ה-method accounts.productreviews.insert
מקבל משאב productreview
ושם של מקור נתונים כקלט. אם הפעולה מסתיימת ללא שגיאות, הפונקציה מחזירה את הערך החדש או המעודכן של productreview
. כדי ליצור ביקורת על מוצר, צריך להיות לכם datasource.name
.
אופן הבקשה:
POST https://merchantapi.googleapis.com/reviews/v1beta/{parent=accounts/{ACCOUNT_ID}/}productReviews:insert
בקשת הדוגמה הבאה ממחישה איך אפשר ליצור ביקורת על מוצר.
POST https://merchantapi.googleapis.com/reviews/v1beta/accounts/{ACCOUNT_ID}/productReviews:insert?dataSource=accounts/{ACCOUNT_ID}/dataSources/{DATASOURCE_ID}
productReviewId = 'my_product_review'
productReviewAttributes {
aggregatorName = 'aggregator_name'
subclientName = 'subclient_name'
publisherName = 'publisher_name'
publisherFavicon = 'https://www.google.com/favicon.ico'
reviewerId = 'reviewer_id'
reviewerIsAnonymous = false
reviewerUsername = 'reviewer_username'
reviewLanguage = 'en'
reviewCountry = 'US'
reviewTime = '2024-04-01T00:00:00Z'
title = 'Incredible product'
content = 'This is an incredible product.'
pros = ['pro1', 'pro2']
cons = ['con1', 'con2']
reviewLink = {
type = 'SINGLETON'
link = 'https://www.google.com'
}
reviewerImageLink = 'https://www.google.com/reviewer.png'
minRating = 1
maxRating = 10
rating = 8.5
productName = 'product_name'
productLink = 'https://www.google.com/product'
asins = ['asin1', 'asin2']
gtins = ['gtin1', 'gtin2']
mpns = ['mpn1', 'mpn2']
skus = ['sku1', 'sku2']
brands = ['brand1', 'brand2']
isSpam = false
collectionMethod = 'POST_FULFILLMENT'
transactionId = 'transaction_id'
}
אחרי שיוצרים ביקורת על מוצר, יכול להיות שיעברו כמה דקות עד שהביקורת תופץ.
הנה דוגמה לקוד שאפשר להשתמש בו כדי להוסיף כמה ביקורות על מוצרים באופן אסינכרוני:
Java
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.reviews.v1beta.ListProductReviewsRequest;
import com.google.shopping.merchant.reviews.v1beta.ProductReview;
import com.google.shopping.merchant.reviews.v1beta.ProductReviewsServiceClient;
import com.google.shopping.merchant.reviews.v1beta.ProductReviewsServiceClient.ListProductReviewsPagedResponse;
import com.google.shopping.merchant.reviews.v1beta.ProductReviewsServiceSettings;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/** This class demonstrates how to list all the product reviews in a given account. */
public class ListProductReviewsSample {
public static void listProductReviews(String accountId) throws Exception {
GoogleCredentials credential = new Authenticator().authenticate();
ProductReviewsServiceSettings productReviewsServiceSettings =
ProductReviewsServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
try (ProductReviewsServiceClient productReviewsServiceClient =
ProductReviewsServiceClient.create(productReviewsServiceSettings)) {
ListProductReviewsRequest request =
ListProductReviewsRequest.newBuilder()
.setParent(String.format("accounts/%s", accountId))
.build();
System.out.println("Sending list product reviews request:");
ListProductReviewsPagedResponse response =
productReviewsServiceClient.listProductReviews(request);
int count = 0;
// Iterates over all rows in all pages and prints all product reviews.
for (ProductReview element : response.iterateAll()) {
System.out.println(element);
count++;
}
System.out.print("The following count of elements were returned: ");
System.out.println(count);
} catch (Exception e) {
System.out.println(e);
}
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
listProductReviews(config.getAccountId().toString());
}
}
אחזור של ביקורת על מוצר
כדי להציג ביקורת על מוצר, משתמשים ב-accounts.productreviews.get
. השדה הזה הוא לקריאה בלבד.
צריך להזין את accountId
ואת המזהה של ביקורת המוצר כחלק משדה השם. השיטה GET
מחזירה את המשאב התואם של הביקורת על המוצר.
GET https://merchantapi.googleapis.com/reviews/v1beta/{name=accounts/{ACCOUNT_ID}/productReviews/*}
לפניכם דוגמה לשימוש באחזור של ביקורת על מוצר:
Java
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.reviews.v1beta.GetProductReviewRequest;
import com.google.shopping.merchant.reviews.v1beta.ProductReview;
import com.google.shopping.merchant.reviews.v1beta.ProductReviewsServiceClient;
import com.google.shopping.merchant.reviews.v1beta.ProductReviewsServiceSettings;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/** This class demonstrates how to get a product review. */
public class GetProductReviewSample {
public static void getProductReview(String accountId, String productReviewId) throws Exception {
GoogleCredentials credential = new Authenticator().authenticate();
ProductReviewsServiceSettings productReviewsServiceSettings =
ProductReviewsServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
try (ProductReviewsServiceClient productReviewsServiceClient =
ProductReviewsServiceClient.create(productReviewsServiceSettings)) {
GetProductReviewRequest request =
GetProductReviewRequest.newBuilder()
.setName(String.format("accounts/%s/productReviews/%s", accountId, productReviewId))
.build();
System.out.println("Sending get product review request:");
ProductReview response = productReviewsServiceClient.getProductReview(request);
System.out.println("Product review retrieved successfully:");
System.out.println(response.getName());
} catch (Exception e) {
System.out.println(e);
}
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
String productReviewId = "YOUR_PRODUCT_REVIEW_ID";
getProductReview(config.getAccountId().toString(), productReviewId);
}
}
הצגת רשימה של ביקורות על מוצרים
אפשר להשתמש בשיטה productreviews.list
כדי להציג את כל ביקורות המוצר שנוצרו.
GET https://merchantapi.googleapis.com/reviews/v1beta/{parent=accounts/{ACCOUNT_ID}}/productReviews
הנה דוגמה לשימוש שאפשר לעשות כדי לקבל רשימה של כל הביקורות על מוצר:
Java
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.reviews.v1beta.ListProductReviewsRequest;
import com.google.shopping.merchant.reviews.v1beta.ProductReview;
import com.google.shopping.merchant.reviews.v1beta.ProductReviewsServiceClient;
import com.google.shopping.merchant.reviews.v1beta.ProductReviewsServiceClient.ListProductReviewsPagedResponse;
import com.google.shopping.merchant.reviews.v1beta.ProductReviewsServiceSettings;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/** This class demonstrates how to list all the product reviews in a given account. */
public class ListProductReviewsSample {
public static void listProductReviews(String accountId) throws Exception {
GoogleCredentials credential = new Authenticator().authenticate();
ProductReviewsServiceSettings productReviewsServiceSettings =
ProductReviewsServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
try (ProductReviewsServiceClient productReviewsServiceClient =
ProductReviewsServiceClient.create(productReviewsServiceSettings)) {
ListProductReviewsRequest request =
ListProductReviewsRequest.newBuilder()
.setParent(String.format("accounts/%s", accountId))
.build();
System.out.println("Sending list product reviews request:");
ListProductReviewsPagedResponse response =
productReviewsServiceClient.listProductReviews(request);
int count = 0;
// Iterates over all rows in all pages and prints all product reviews.
for (ProductReview element : response.iterateAll()) {
System.out.println(element);
count++;
}
System.out.print("The following count of elements were returned: ");
System.out.println(count);
} catch (Exception e) {
System.out.println(e);
}
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
listProductReviews(config.getAccountId().toString());
}
}
מחיקת ביקורות על מוצרים
כדי למחוק ביקורת על מוצר, משתמשים ב-accounts.productreviews.delete
. בדומה לשיטה GET
, גם בשיטה הזו צריך לציין את השדה name של הביקורת על המוצר שמוחזרת במהלך היצירה.
DELETE https://merchantapi.googleapis.com/reviews/v1beta/{name=accounts/{ACCOUNT_ID}/productReviews/*}
לפניכם דוגמה שאפשר להשתמש בה כדי למחוק ביקורת על מוצר:
Java
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.reviews.v1beta.DeleteProductReviewRequest;
import com.google.shopping.merchant.reviews.v1beta.ProductReviewsServiceClient;
import com.google.shopping.merchant.reviews.v1beta.ProductReviewsServiceSettings;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/** This class demonstrates how to delete a product review. */
public class DeleteProductReviewSample {
public static void deleteProductReview(String accountId, String productReviewId)
throws Exception {
GoogleCredentials credential = new Authenticator().authenticate();
ProductReviewsServiceSettings productReviewsServiceSettings =
ProductReviewsServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
try (ProductReviewsServiceClient productReviewsServiceClient =
ProductReviewsServiceClient.create(productReviewsServiceSettings)) {
DeleteProductReviewRequest request =
DeleteProductReviewRequest.newBuilder()
.setName(String.format("accounts/%s/productReviews/%s", accountId, productReviewId))
.build();
System.out.println("Sending delete product review request:");
productReviewsServiceClient.deleteProductReview(request);
System.out.println("Product review deleted successfully");
} catch (Exception e) {
System.out.println(e);
}
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
String productReviewId = "YOUR_PRODUCT_REVIEW_ID";
deleteProductReview(config.getAccountId().toString(), productReviewId);
}
}
סטטוס בדיקת המוצר
המשאב של בדיקת המוצר מכיל סטטוס דומה לממשקי API אחרים, שהוא חלק בלתי נפרד מהמשאב ופועל לפי אותה מבנה של בעיות ויעדים.