產品評論是消費者購物體驗的重要一環。這些評分和評論有助於顧客研究產品與決定消費,正面的產品評論可以吸引更多符合資格的顧客瀏覽賣家的產品頁面。來源包括賣家、評論集結網站、評論網站和 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 總覽」。
建立產品評論
您可以使用 accounts.productreviews.insert
方法建立或更新產品評論。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'
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'
}
建立產品評論後,系統可能需要幾分鐘的時間才能發布。
以下是可用於不同步插入多個產品評論的範例:
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
和產品評論 ID。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
方法類似,這個方法需要在建立時傳回的產品評論名稱欄位。
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 類似,是資源的必要部分,並遵循相同的問題與目的地結構。