Le recensioni del venditore aiutano le persone a trovare attività che offrono customer experience di alta qualità, contribuendo a creare fiducia e consentendo di prendere decisioni di acquisto più consapevoli. Di conseguenza, le valutazioni negozio possono aiutare le attività a migliorare il rendimento degli annunci e delle schede organiche e indirizzare clienti più qualificati alle loro pagine di destinazione.
Questa pagina spiega come gestire le recensioni del venditore utilizzando l'API Merchant.
Prerequisiti
Google ha bisogno che tu fornisca informazioni specifiche. Devi avere quanto segue:
- Un'origine dei dati delle recensioni del commerciante attiva in Google Merchant Center.
- Il tuo account deve essere registrato al programma di valutazioni negozio. Se non sai se hai già eseguito la registrazione, controlla Merchant Center. Se non hai eseguito la registrazione, invia il modulo di richiesta.
Creare un'origine dati
Utilizza il
accounts.dataSources.create
per creare un feed delle recensioni del commerciante. Se è disponibile un feed delle recensioni del commerciante esistente, utilizza
accounts.dataSources.get
per recuperare il campo dataSource.name.
Il modulo della richiesta è il seguente:
POST https://merchantapi.googleapis.com/datasources/v1/accounts/{ACCOUNT_ID}/dataSources/{DATASOURCE_ID}
Esempio
L'esempio mostra una richiesta e una risposta tipiche.
Richiesta
POST https://merchantapi.googleapis.com/datasources/v1/accounts/123/dataSources {"displayName": "test api feed", "merchantReviewDataSource":{} }
Risposta
{
"name": "accounts/123/dataSources/1000000573361824",
"dataSourceId": "1000000573361824",
"displayName": "test api feed",
"merchantReviewDataSource": {},
"input": "API"
}
Per saperne di più, vedi Creare un'origine dei dati delle recensioni prodotto.
Creare una recensione del commerciante
Puoi utilizzare il
accounts.merchantReviews.insert
metodo per creare o aggiornare una recensione del venditore. Il metodo accounts.merchantReviews.insert accetta come input una risorsa merchantreview e un nome dell'origine dei dati. Se l'operazione va a buon fine, restituisce la recensione del commerciante nuova o aggiornata. Per creare una recensione del commerciante è necessario datasource.name.
Il modulo della richiesta:
POST https://merchantapi.googleapis.com/reviews/v1alpha/{parent=accounts/*/}merchantReviews:insert
Per riferimento, studia la seguente recensione del commerciante di esempio.
POST https://merchantapi.googleapis.com/reviews/v1alpha/accounts/{ACCOUNT_ID}/merchantReviews:insert?dataSource=accounts/{ACCOUNT_ID}/dataSources/{DATASOURCE_ID}
merchantReviewId = 'my_own_review'
merchantReviewAttributes {
merchantId = 'merchant_id'
merchantDisplayName = 'merchant_display_name'
merchantLink = 'publisher_name'
merchantRatingLink = 'https://www.google.com'
minRating = 1
maxRating = 10
rating = 7.9
title = 'Amazing Merchant'
content = 'This is an incredible merchant'
reviewerId = 'reviewer_id'
reviewerUsername = 'reviewer_username'
isAnonymous = false
collectionMethod = 'AFTER_FULFILLMENT'
reviewTime = '2024-04-01T00:00:00Z'
reviewLanguage = 'en'
reviewCountry = 'US'
}
Dopo la creazione della recensione del commerciante, potrebbero essere necessari alcuni minuti prima che venga propagata.
Visualizzare le recensioni del commerciante
Per visualizzare una recensione del commerciante, utilizza
accounts.merchantReviews.get.
Questo campo è di sola lettura. Richiede il tuo merchantId e l'ID della recensione del commerciante come parte del campo name. Il metodo get restituisce la risorsa della recensione del commerciante corrispondente.
Ad esempio:
GET https://merchantapi.googleapis.com/reviews/v1alpha/{name=accounts/*/merchantReviews/*}
Per recuperare un singolo prodotto per un determinato account Merchant Center, puoi utilizzare
il
google.shopping.merchant.accounts.v1.GetProductRequest
metodo, come mostrato nell'esempio seguente.
Java
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.common.io.BaseEncoding;
import com.google.shopping.merchant.products.v1.GetProductRequest;
import com.google.shopping.merchant.products.v1.Product;
import com.google.shopping.merchant.products.v1.ProductsServiceClient;
import com.google.shopping.merchant.products.v1.ProductsServiceSettings;
import java.nio.charset.StandardCharsets;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/** This class demonstrates how to get a single product for a given Merchant Center account */
public class GetProductSample {
// Base64Url encoder/decoder without padding
private static final BaseEncoding BASE64URL_NOPADDING = BaseEncoding.base64Url().omitPadding();
// Encodes a string to base64url without padding
public static String encodeProductId(String productId) {
return BASE64URL_NOPADDING.encode(productId.getBytes(StandardCharsets.UTF_8));
}
public static void getProduct(Config config, String accountId, String productId)
throws Exception {
// Obtains OAuth token based on the user's configuration.
GoogleCredentials credential = new Authenticator().authenticate();
// Creates service settings using the credentials retrieved above.
ProductsServiceSettings productsServiceSettings =
ProductsServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
// Calls the API and catches and prints any network failures/errors.
try (ProductsServiceClient productsServiceClient =
ProductsServiceClient.create(productsServiceSettings)) {
// The name has the format: accounts/{account}/products/{productId}
String name = "accounts/" + accountId + "/products/" + productId;
// The name has the format: accounts/{account}/products/{productId}
GetProductRequest request = GetProductRequest.newBuilder().setName(name).build();
System.out.println("Sending get product request:");
Product response = productsServiceClient.getProduct(request);
System.out.println("Retrieved Product below");
System.out.println(response);
} catch (Exception e) {
System.out.println(e);
}
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
String accountId = config.getAccountId().toString();
// The name of the `product`, returned after a `Product.insert` request. We recommend
// having stored this value in your database to use for all future requests.
String productId = "en~US~sku123"; // Replace with your actual product ID
// Uncomment the following line if the product name contains special characters (such as forward
// slashes) and needs base64url encoding.
// productId = encodeProductId(productId);
getProduct(config, accountId, productId);
}
}
Elencare le recensioni del commerciante
Puoi utilizzare il
accounts.merchantReviews.list
metodo per visualizzare tutte le recensioni del commerciante create.
GET https://merchantapi.googleapis.com/reviews/v1alpha/accounts/{ACCOUNT_ID}/merchantReviews
Eliminare le recensioni del commerciante
Per eliminare una recensione del commerciante, utilizza
accounts.merchantReviews.delete.
Analogamente al metodo accounts.merchantReviews.get, questo metodo richiede il campo name della recensione del commerciante restituito durante la creazione.
Ad esempio:
DELETE https://merchantapi.googleapis.com/reviews/v1alpha/{name=accounts/*/merchantReviews/*}
Stato della recensione del commerciante
La risorsa della recensione del commerciante contiene lo stato simile ad altre API, che è parte integrante della risorsa e segue la stessa struttura di problemi e destinazioni.