Ürün yorumları, müşterilerin Alışveriş deneyiminin önemli bir parçasıdır. Bu puanlar ve yorumlar, müşterilere ürün araştırma ve satın alma kararlarında yardımcı olur. Olumlu ürün yorumları, satıcının ürün sayfalarına daha nitelikli müşteriler çekebilir. Bu kaynaklar arasında satıcılar, yorum toplayıcılar, yorum siteleri ve Google kullanıcıları yer alır.
Bu sayfada, Merchant API'yi kullanarak ürün yorumlarını nasıl yönetebileceğiniz açıklanmaktadır.
Ön koşullar
Google'ın belirli bilgileri sağlamanız gerekir. Aşağıdakilere sahip olmanız gerekir:
- Google Merchant Center'da etkin bir ürün yorumları feed'i
- Hesabınızın Ürün Puanları programına kayıtlı olması gerekir. Uygunluk durumunu Programs alt API'sini kullanarak programatik olarak veya Merchant Center üzerinden kontrol edebilirsiniz. Uygun değilseniz ürün puanları programına kaydolma hakkında daha fazla bilgi edinin.
- Merchant API'yi kullanarak ürünleri incelemek için Alışveriş API'si Destek Formu'nda "Sorun/soru nedir?" bölümünden izin verilenler listesi isteği gönderin.
Veri kaynağı oluşturma
Ürün yorumları feed'i oluşturmak için datasource.create yöntemini kullanın. Mevcut bir satıcı veya ürün yorumu feed'i varsa accounts.dataSources.name değerini almak için accounts.dataSources.list yöntemini kullanın. Oluşturduğunuz veya aldığınız veri kaynağı adını her yorum için yerel veritabanınızda depolayın. İstek şu şekilde biçimlendirilir:
POST https://merchantapi.googleapis.com/datasources/v1/accounts/{ACCOUNT_ID}/dataSources
Örnek
Örnekte tipik bir istek ve yanıt gösterilmektedir:
İstek
POST https://merchantapi.googleapis.com/datasources/v1/accounts/{ACCOUNT_ID}/dataSources
{
"displayName": "My API Data Source",
"primaryProductDataSource": {}
}
Yanıt
{
"name": "accounts/{ACCOUNT_ID}/dataSources/{DATASOURCE_ID}",
"dataSourceId": "{DATASOURCE_ID}",
"displayName": "My API Data Source",
"primaryProductDataSource": {},
"input": "API"
}
Daha fazla bilgi için Ürün yorumu veri kaynağı oluşturma başlıklı makaleyi inceleyin.
Ürün yorumu oluşturma
Ürün yorumu oluşturmak veya güncellemek için accounts.productreviews.insert yöntemini kullanabilirsiniz. accounts.productreviews.insert yöntemi, giriş olarak bir productreview kaynağı ve veri kaynağı adı alır. İşlem başarılı olursa yeni veya güncellenmiş productreview döndürülür. Ürün yorumu oluşturmak için datasource.name hesabınızın olması gerekir.
Talebin biçimi:
POST https://merchantapi.googleapis.com/reviews/v1/{parent=accounts/{ACCOUNT_ID}/}productReviews:insert
Aşağıdaki örnek istekte, ürün yorumu oluşturma işlemi gösterilmektedir.
POST https://merchantapi.googleapis.com/reviews/v1/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'
}
Ürün yorumu oluşturulduktan sonra yorumun yayınlanması birkaç dakika sürebilir.
Birden fazla ürün yorumunu eşzamansız olarak eklemek için kullanabileceğiniz bir örnek aşağıda verilmiştir:
Java
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.v1.InsertProductReviewRequest;
import com.google.shopping.merchant.reviews.v1.ProductReview;
import com.google.shopping.merchant.reviews.v1.ProductReviewAttributes;
import com.google.shopping.merchant.reviews.v1.ProductReviewAttributes.ReviewLink;
import com.google.shopping.merchant.reviews.v1.ProductReviewAttributes.ReviewLink.Type;
import com.google.shopping.merchant.reviews.v1.ProductReviewsServiceClient;
import com.google.shopping.merchant.reviews.v1.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");
}
}
Ürün yorumu alma
Ürün yorumlarını görüntülemek için accounts.productreviews.get kullanın. Bu salt okunurdur.
Ad alanının bir parçası olarak accountId ve ürün yorumunun kimliği gerekir. GET yöntemi, ilgili ürün yorumu kaynağını döndürür.
GET https://merchantapi.googleapis.com/reviews/v1/{name=accounts/{ACCOUNT_ID}/productReviews/*}
Ürün yorumu almak için kullanabileceğiniz bir örnek aşağıda verilmiştir:
Java
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.reviews.v1.GetProductReviewRequest;
import com.google.shopping.merchant.reviews.v1.ProductReview;
import com.google.shopping.merchant.reviews.v1.ProductReviewsServiceClient;
import com.google.shopping.merchant.reviews.v1.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);
}
}
Ürün yorumlarını listeleme
Oluşturulan tüm ürün yorumlarını görüntülemek için productreviews.list yöntemini kullanabilirsiniz.
GET https://merchantapi.googleapis.com/reviews/v1/{parent=accounts/{ACCOUNT_ID}}/productReviews
Bir ürünle ilgili tüm yorumları listelemek için kullanabileceğiniz bir örnek aşağıda verilmiştir:
Java
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.reviews.v1.ListProductReviewsRequest;
import com.google.shopping.merchant.reviews.v1.ProductReview;
import com.google.shopping.merchant.reviews.v1.ProductReviewsServiceClient;
import com.google.shopping.merchant.reviews.v1.ProductReviewsServiceClient.ListProductReviewsPagedResponse;
import com.google.shopping.merchant.reviews.v1.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());
}
}
Ürün yorumlarını silme
Ürün yorumlarını silmek için accounts.productreviews.delete kullanın. GET yöntemine benzer şekilde, bu yöntem de oluşturma sırasında döndürülen ürün yorumunun ad alanını gerektirir.
DELETE https://merchantapi.googleapis.com/reviews/v1/{name=accounts/{ACCOUNT_ID}/productReviews/*}
Ürün yorumlarını silmek için kullanabileceğiniz bir örnek:
Java
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.reviews.v1.DeleteProductReviewRequest;
import com.google.shopping.merchant.reviews.v1.ProductReviewsServiceClient;
import com.google.shopping.merchant.reviews.v1.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);
}
}
Ürün yorumu durumu
Ürün yorumu kaynağı, diğer API'lere benzer bir durum içerir. Bu durum, kaynağın ayrılmaz bir parçasıdır ve aynı sorun ve hedef yapısını izler.