제품 리뷰는 고객의 쇼핑 경험 에서 중요한 부분입니다. 제품 평가 및 리뷰는 고객의 제품 조사 및 구매 결정을 돕습니다. 긍정적인 제품 리뷰는 구매 가능성이 큰 고객을 판매자의 제품 페이지로 유도할 수 있습니다. 소스에는 판매자, 리뷰 애그리게이터, 리뷰 사이트, Google 사용자가 포함됩니다.
이 페이지에서는 Merchant API를 사용하여 제품 리뷰를 관리하는 방법을 설명합니다.
기본 요건
Google에서는 판매자가 특정 정보를 제공해야 합니다. 다음이 있어야 합니다.
- Google 판매자 센터에 활성 제품 리뷰 피드가 있어야 합니다.
- 계정이 제품 평가 프로그램에 등록되어 있어야 합니다. 프로그램 하위 API를 사용하여 프로그래매틱 방식으로 적격성을 확인하거나 판매자 센터를 통해 확인할 수 있습니다.적격하지 않은 경우 제품 평가 프로그램 등록에 대해 자세히 알아보세요.
- Merchant API를 사용하여 제품을 검토하려면 쇼핑 API 지원 양식 의 "문제/질문"에서 허용 목록 요청을 제출하세요.
데이터 소스 만들기
datasource.create 메서드를 사용하여 제품 리뷰 피드를 만듭니다. 기존 판매자 또는 제품 리뷰 피드를 사용할 수 있는 경우
accounts.dataSources.list
를 사용하여 accounts.dataSources.name를 가져옵니다. 각 리뷰에 대해 생성하거나 가져온 데이터 소스 이름을 로컬 데이터베이스에 저장합니다. 요청의 형식은 다음과 같습니다.
POST https://merchantapi.googleapis.com/datasources/v1/accounts/{ACCOUNT_ID}/dataSources
예
이 예에서는 일반적인 요청 및 응답을 보여줍니다.
요청
POST https://merchantapi.googleapis.com/datasources/v1/accounts/{ACCOUNT_ID}/dataSources
{
"displayName": "My API Data Source",
"primaryProductDataSource": {}
}
응답
{
"name": "accounts/{ACCOUNT_ID}/dataSources/{DATASOURCE_ID}",
"dataSourceId": "{DATASOURCE_ID}",
"displayName": "My API Data Source",
"primaryProductDataSource": {},
"input": "API"
}
자세한 내용은 제품 리뷰 데이터 소스 만들기를 참고하세요.
제품 리뷰 만들기
accounts.productreviews.insert 메서드를 사용하여 제품 리뷰를 만들거나 업데이트할 수 있습니다. accounts.productreviews.insert 메서드는
productreview 리소스와 데이터 소스 이름을 입력으로 사용합니다. 성공하면 새 productreview 또는 업데이트된 productreview를 반환합니다. 제품 리뷰를 만들려면
다음을
datasource.name 가지고 있어야 합니다.
요청의 형식은 다음과 같습니다.
POST https://merchantapi.googleapis.com/reviews/v1alpha/{parent=accounts/{ACCOUNT_ID}/}productReviews:insert
다음 샘플 요청은 제품 리뷰를 만드는 방법을 보여줍니다.
POST https://merchantapi.googleapis.com/reviews/v1alpha/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'
}
reviewerImageLinks = ['https://www.google.com/reviewer.png']
minRating = 1
maxRating = 10
rating = 8.5
productNames = ['product_name']
productLinks = ['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'
}
제품 리뷰를 만든 후 리뷰가 전파되는 데 몇 분 정도 걸릴 수 있습니다.
다음은 여러 제품 리뷰를 비동기식으로 삽입하는 데 사용할 수 있는 샘플입니다.
자바
import com.google.api.core.ApiFuture;
import com.google.api.core.ApiFutureCallback;
import com.google.api.core.ApiFutures;
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.protobuf.Timestamp;
import com.google.shopping.merchant.reviews.v1alpha.InsertProductReviewRequest;
import com.google.shopping.merchant.reviews.v1alpha.ProductReview;
import com.google.shopping.merchant.reviews.v1alpha.ProductReviewAttributes;
import com.google.shopping.merchant.reviews.v1alpha.ProductReviewAttributes.ReviewLink;
import com.google.shopping.merchant.reviews.v1alpha.ProductReviewAttributes.ReviewLink.Type;
import com.google.shopping.merchant.reviews.v1alpha.ProductReviewsServiceClient;
import com.google.shopping.merchant.reviews.v1alpha.ProductReviewsServiceSettings;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/** This class demonstrates how to insert multiple product reviews asynchronously. */
public class InsertProductReviewsAsyncSample {
private static String generateRandomString() {
String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
Random random = new Random();
StringBuilder sb = new StringBuilder(8);
for (int i = 0; i < 8; i++) {
sb.append(characters.charAt(random.nextInt(characters.length())));
}
return sb.toString();
}
// Returns a product review with a random ID.
private static ProductReview createProductReview(String accountId) {
// MAKE SURE YOU PASS AN ACTUAL PRODUCT REVIEW ID HERE.
String productReviewId = generateRandomString();
ProductReviewAttributes attributes =
ProductReviewAttributes.newBuilder()
.setTitle("Would not recommend!")
.setContent("Not fantastic.")
.setMinRating(1)
.setMaxRating(5)
.setRating(2)
.setReviewTime(Timestamp.newBuilder().setSeconds(123456789).build())
.addProductLinks("exampleproducturl.com")
.setReviewLink(
ReviewLink.newBuilder()
.setLink("examplereviewurl.com")
// The review page contains only this single review.
.setType(Type.SINGLETON)
.build())
.addGtins("9780007350896")
.addGtins("9780007350897")
.build();
return ProductReview.newBuilder()
.setProductReviewId(productReviewId)
.setProductReviewAttributes(attributes)
.build();
}
public static void asyncInsertProductReviews(String accountId, String dataSourceId)
throws Exception {
GoogleCredentials credential = new Authenticator().authenticate();
ProductReviewsServiceSettings productReviewsServiceSettings =
ProductReviewsServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
try (ProductReviewsServiceClient productReviewsServiceClient =
ProductReviewsServiceClient.create(productReviewsServiceSettings)) {
// Arbitrarily creates five product reviews with random IDs.
List<InsertProductReviewRequest> requests = new ArrayList<>();
for (int i = 0; i < 5; i++) {
InsertProductReviewRequest request =
InsertProductReviewRequest.newBuilder()
.setParent(String.format("accounts/%s", accountId))
.setProductReview(createProductReview(accountId))
// Must be a product reviews data source. In other words, a data source whose "type"
// is ProductReviewDataSource.
.setDataSource(String.format("accounts/%s/dataSources/%s", accountId, dataSourceId))
.build();
requests.add(request);
}
// Inserts the product reviews.
List<ApiFuture<ProductReview>> futures =
requests.stream()
.map(
request ->
productReviewsServiceClient.insertProductReviewCallable().futureCall(request))
.collect(Collectors.toList());
// Creates callback to handle the responses when all are ready.
ApiFuture<List<ProductReview>> responses = ApiFutures.allAsList(futures);
ApiFutures.addCallback(
responses,
new ApiFutureCallback<List<ProductReview>>() {
@Override
public void onSuccess(List<ProductReview> results) {
System.out.println("Inserted product reviews below:");
System.out.println(results);
}
@Override
public void onFailure(Throwable throwable) {
System.out.println(throwable);
}
},
MoreExecutors.directExecutor());
} catch (Exception e) {
System.out.println(e);
}
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
asyncInsertProductReviews(config.getAccountId().toString(), "YOUR_DATA_SOURCE_ID");
}
}
제품 리뷰 가져오기
제품 리뷰를 보려면 accounts.productreviews.get을 사용합니다. 읽기 전용입니다.
이름 필드의 일부로 accountId와 제품 리뷰의 ID가 필요합니다. GET 메서드는 해당 제품 리뷰 리소스를 반환합니다.
GET https://merchantapi.googleapis.com/reviews/v1alpha/{name=accounts/{ACCOUNT_ID}/productReviews/*}
다음은 제품 리뷰를 가져오는 데 사용할 수 있는 샘플입니다.
자바
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.reviews.v1alpha.GetProductReviewRequest;
import com.google.shopping.merchant.reviews.v1alpha.ProductReview;
import com.google.shopping.merchant.reviews.v1alpha.ProductReviewsServiceClient;
import com.google.shopping.merchant.reviews.v1alpha.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/v1alpha/{parent=accounts/{ACCOUNT_ID}}/productReviews
다음은 제품의 모든 리뷰를 나열하는 데 사용할 수 있는 샘플입니다.
자바
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.reviews.v1alpha.ListProductReviewsRequest;
import com.google.shopping.merchant.reviews.v1alpha.ProductReview;
import com.google.shopping.merchant.reviews.v1alpha.ProductReviewsServiceClient;
import com.google.shopping.merchant.reviews.v1alpha.ProductReviewsServiceClient.ListProductReviewsPagedResponse;
import com.google.shopping.merchant.reviews.v1alpha.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/v1alpha/{name=accounts/{ACCOUNT_ID}/productReviews/*}
다음은 제품 리뷰를 삭제하는 데 사용할 수 있는 샘플입니다.
자바
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.reviews.v1alpha.DeleteProductReviewRequest;
import com.google.shopping.merchant.reviews.v1alpha.ProductReviewsServiceClient;
import com.google.shopping.merchant.reviews.v1alpha.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와 유사한 상태가 포함되어 있으며, 이는 리소스의 필수적인 부분이며 동일한 문제 및 대상 구조를 따릅니다.