对使用 Merchant API 的卖家进行评价

卖家评价能帮助用户发现提供 优质客户体验的商家,对商家产生信任感,从而做出更 明智的购买决定。因此,商店评分有助于商家提升广告和自然搜索结果的效果,吸引更多符合条件的客户访问其着陆页。

本页面介绍了如何使用 Merchant API 管理卖家评价。

前提条件

Google 需要您提供特定信息。您必须具备以下条件:

  • 在 Google Merchant Center 中拥有有效卖家评价数据源。
  • 您的账号必须已注册商店评分 计划。如果您不确定自己是否已注册,请查看 Merchant Center。如果您尚未注册,请提交申请表

创建数据源

使用 accounts.dataSources.create 方法创建卖家评价 Feed。如果有现有的卖家评价 Feed,请使用 accounts.dataSources.get 来提取 dataSource.name 字段。

请求的格式如下:

POST https://merchantapi.googleapis.com/datasources/v1/accounts/{ACCOUNT_ID}/dataSources/{DATASOURCE_ID}

示例

该示例展示了一个典型的请求和响应。

请求

POST https://merchantapi.googleapis.com/datasources/v1/accounts/123/dataSources {"displayName": "test api feed", "merchantReviewDataSource":{} }

答案

{
  "name": "accounts/123/dataSources/1000000573361824",
  "dataSourceId": "1000000573361824",
  "displayName": "test api feed",
  "merchantReviewDataSource": {},
  "input": "API"
}

如需了解详情,请参阅创建商品评价数据 源

创建卖家评价

您可以使用 accounts.merchantReviews.insert 方法创建或更新卖家评价。accounts.merchantReviews.insert 方法将 merchantreview 资源和数据源名称作为输入。如果成功,该方法会返回新的或更新后的卖家评价。创建卖家评价需要 datasource.name

请求的格式:

POST https://merchantapi.googleapis.com/reviews/v1alpha/{parent=accounts/*/}merchantReviews:insert

请研究以下卖家评价示例以供参考。

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'
  }

创建卖家评价后,评价可能需要几分钟才能传播。

查看卖家评价

如需查看卖家评价,请使用 accounts.merchantReviews.get. 此方法为只读方法。它需要您的 merchantId 和卖家评价的 ID 作为名称字段的一部分。get 方法会返回相应的卖家评价资源。

例如:

GET https://merchantapi.googleapis.com/reviews/v1alpha/{name=accounts/*/merchantReviews/*}

如需检索给定 Merchant Center 账号的单个商品,您可以使用 the google.shopping.merchant.accounts.v1.GetProductRequest 方法,如以下示例所示。

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);
  }
}

列出卖家评价

您可以使用 accounts.merchantReviews.list 方法查看所有已创建的卖家评价。

GET https://merchantapi.googleapis.com/reviews/v1alpha/accounts/{ACCOUNT_ID}/merchantReviews

删除卖家评价

如需删除卖家评价,请使用 accounts.merchantReviews.delete。 与 accounts.merchantReviews.get 方法类似,此方法需要创建期间返回的卖家评价的名称字段。

例如:

DELETE https://merchantapi.googleapis.com/reviews/v1alpha/{name=accounts/*/merchantReviews/*}

卖家评价状态

卖家评价资源包含与其他 API 类似的状态,这是资源的组成部分,遵循相同的问题和目标结构。