Bài đánh giá sản phẩm là một phần quan trọng trong trải nghiệm Mua sắm của khách hàng. Điểm xếp hạng và bài đánh giá này giúp khách hàng tìm hiểu về sản phẩm và đưa ra quyết định mua hàng. Bài đánh giá sản phẩm tích cực có thể thu hút thêm nhiều khách hàng đủ tiêu chuẩn đến các trang sản phẩm của người bán. Các nguồn bao gồm người bán, trang web tổng hợp bài đánh giá, trang web đánh giá và người dùng Google.
Trang này giải thích cách bạn có thể quản lý bài đánh giá sản phẩm bằng Merchant API.
Điều kiện tiên quyết
Google cần bạn cung cấp thông tin cụ thể. Bạn phải có:
- Nguồn cấp dữ liệu bài đánh giá sản phẩm đang hoạt động trong Google Merchant Center.
- Tài khoản của bạn phải được đăng ký tham gia chương trình Xếp hạng sản phẩm. Nếu bạn không chắc chắn liệu mình đã đăng ký hay chưa, hãy kiểm tra Merchant Center. Nếu bạn chưa đăng ký, hãy tìm hiểu thêm về cách đăng ký tham gia chương trình điểm xếp hạng sản phẩm.
- Để xem xét sản phẩm bằng Merchant API, hãy gửi yêu cầu thông qua biểu mẫu này.
Tạo một nguồn dữ liệu
Sử dụng API datasource.create
để tạo nguồn cấp dữ liệu bài đánh giá sản phẩm. Nếu có nguồn cấp dữ liệu đánh giá sản phẩm hiện có, hãy sử dụng accounts.dataSources.get
để tìm nạp accounts.dataSources.name
. Dạng của yêu cầu như sau:
POST https://merchantapi.googleapis.com/datasources/v1beta/accounts/{account}/dataSources/{datasource}
Ví dụ:
Ví dụ này cho thấy một yêu cầu và phản hồi thông thường.
Yêu cầu
POST https://merchantapi.googleapis.com/datasources/v1beta/accounts/123/dataSources {"displayName": "test api feed", "productReviewDataSource":{} }
Đáp
{
"name": "accounts/123/dataSources/1000000573361824",
"dataSourceId": "1000000573361824",
"displayName": "test api feed",
"productReviewDataSource": {},
"input": "API"
}
Để biết thêm thông tin, hãy xem bài viết Tổng quan về API nguồn dữ liệu người bán.
Tạo bài đánh giá sản phẩm
Bạn có thể sử dụng phương thức accounts.productreviews.insert
để tạo hoặc cập nhật bài đánh giá sản phẩm. Phương thức accounts.productreviews.insert
lấy tài nguyên productreview
và tên nguồn dữ liệu làm dữ liệu đầu vào. Phương thức này trả về productreview
mới hoặc đã cập nhật nếu thành công. Để tạo bài đánh giá sản phẩm, bạn phải có datasource.name
.
Hình thức của yêu cầu:
POST https://merchantapi.googleapis.com/reviews/v1beta/{parent=accounts/{ACCOUNT_ID} /}productReviews:insert
Yêu cầu mẫu sau đây minh hoạ cách bạn có thể tạo bài đánh giá sản phẩm.
POST https://merchantapi.googleapis.com/reviews/v1beta/accounts/{ACCOUNT_ID} /productReviews:insert?dataSource=accounts/{ACCOUNT_ID} /dataSources/{DATASOURCE_ID}
productReviewId = 'my_product_review'
attributes {
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'
}
Sau khi bạn tạo bài đánh giá sản phẩm, có thể mất vài phút để bài đánh giá đó được truyền tải.
Dưới đây là một mẫu bạn có thể sử dụng để chèn nhiều bài đánh giá sản phẩm một cách không đồng bộ:
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());
}
}
Truy xuất bài đánh giá sản phẩm
Để xem bài đánh giá sản phẩm, hãy sử dụng accounts.productreviews.get
. Thuộc tính này chỉ có thể đọc.
Thuộc tính này yêu cầu accountId
và mã bài đánh giá sản phẩm trong trường tên. Phương thức GET
trả về tài nguyên bài đánh giá sản phẩm tương ứng.
GET https://merchantapi.googleapis.com/reviews/v1beta/{name=accounts/{ACCOUNT_ID} /productReviews/*}
Dưới đây là một mẫu bạn có thể sử dụng để truy xuất bài đánh giá sản phẩm:
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);
}
}
Liệt kê bài đánh giá sản phẩm
Bạn có thể sử dụng phương thức productreviews.list
để xem tất cả bài đánh giá sản phẩm đã tạo.
GET https://merchantapi.googleapis.com/reviews/v1beta/{parent=accounts/{ACCOUNT_ID} }/productReviews
Dưới đây là mẫu mà bạn có thể sử dụng để liệt kê tất cả bài đánh giá về một sản phẩm:
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());
}
}
Xoá bài đánh giá sản phẩm
Để xoá bài đánh giá sản phẩm, hãy sử dụng accounts.productreviews.delete
. Tương tự như phương thức GET
, phương thức này yêu cầu trường tên của bài đánh giá sản phẩm được trả về trong quá trình tạo.
DELETE https://merchantapi.googleapis.com/reviews/v1beta/{name=accounts/{ACCOUNT_ID} /productReviews/*}
Dưới đây là mẫu mà bạn có thể sử dụng để xoá bài đánh giá sản phẩm:
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);
}
}
Trạng thái bài đánh giá sản phẩm
Tài nguyên bài đánh giá sản phẩm chứa trạng thái tương tự như các API khác. Đây là một phần không thể thiếu của tài nguyên và tuân theo cùng một cấu trúc vấn đề và đích đến.