Merchant Products API के बारे में खास जानकारी

इस पेज पर, प्रोग्राम के हिसाब से प्रॉडक्ट अपलोड करने और उन्हें मैनेज करने का तरीका बताया गया है. Merchant Center के प्रॉडक्ट एपीआई का इस्तेमाल करके, डेटा सोर्स में प्रॉडक्ट डाला या अपडेट किया जा सकता है. साथ ही, अपने खाते से प्रॉडक्ट वापस पाया जा सकता है और डेटा सोर्स से प्रॉडक्ट मिटाया जा सकता है.

Merchant Center के प्रॉडक्ट एपीआई में दो संसाधन होते हैं.

  • productInputs, आपके प्रॉडक्ट के इनपुट पार्ट दिखाता है.
  • products, आपके इनपुट पार्ट से बनाए गए प्रोसेस किए गए प्रॉडक्ट दिखाता है.

productInputs को प्राइमरी और सप्लीमेंटरी, दोनों तरह के डेटा सोर्स में अपलोड किया जा सकता है. यह इस बात पर निर्भर करता है कि इसे प्राइमरी डेटा सोर्स या सप्लीमेंटरी डेटा सोर्स में अपलोड किया गया है. हर product को एक प्राइमरी productInput और किसी भी संख्या में पूरक productInputs से बनाया जाएगा.

Merchant Center के प्रॉडक्ट एपीआई का इस्तेमाल करके, ऑनलाइन या स्थानीय स्टोर के कैटलॉग बनाए जा सकते हैं. ये ऐसे प्रॉडक्ट होते हैं जो कई शॉपिंग डेस्टिनेशन पर दिख सकते हैं. Merchant Center खाता बनाने, पहला डेटा सोर्स सेट अप करने, और एपीआई की मदद से प्रॉडक्ट का शुरुआती सेट अपलोड करने के बाद, productInputs संसाधन का इस्तेमाल किया जा सकता है.

कारोबारियों या कंपनियों के पास, PrimaryProductDataSource नाम की फ़ाइल का इस्तेमाल करके प्रॉडक्ट अपलोड करने का विकल्प होता है. हालांकि, Merchant API का इस्तेमाल करके प्रॉडक्ट बनाने और मिटाने के कई फ़ायदे हैं. इन फ़ायदों में, तेज़ी से जवाब मिलने और बड़ी फ़ाइलों को मैनेज किए बिना, प्रॉडक्ट को रीयल टाइम में अपडेट करने की सुविधा शामिल है. एपीआई कॉल की मदद से प्रॉडक्ट में किए गए बदलाव, Shopping के डेटाबेस में दिखने में कई घंटे लग सकते हैं.

ज़रूरी शर्तें

अगर आपके पास कोई डेटा सोर्स नहीं है, तो Merchant Center या Merchant Center API का इस्तेमाल करके डेटा सोर्स बनाएं.

अगर आपके पास पहले से कोई डेटा सोर्स है, जिसे आपने Merchant Center के यूज़र इंटरफ़ेस (यूआई) या एपीआई का इस्तेमाल करके बनाया है, तो अपने प्रॉडक्ट जोड़ने के लिए Merchant Center के प्रॉडक्ट एपीआई का इस्तेमाल किया जा सकता है. अगर प्रॉडक्ट जोड़ने के लिए Content API for Shopping का इस्तेमाल किया जा रहा है, तो Merchant Center के प्रॉडक्ट एपीआई का इस्तेमाल शुरू करने का तरीका जानने के लिए, माइग्रेशन गाइड देखें.

शॉपिंग विज्ञापनों और मुफ़्त में दिखाई जाने वाली लिस्टिंग की नीतियों का पालन करना आपकी ज़िम्मेदारी है. शॉपिंग विज्ञापनों के लिए, इन नीतियों को लागू करने का अधिकार Shopping Ads के पास है. साथ ही, अगर हमें इन नीतियों का उल्लंघन करने वाला कॉन्टेंट या व्यवहार मिलता है, तो हम ज़रूरत के हिसाब से कार्रवाई करेंगे.

संसाधन

products संसाधन की मदद से, Shopping डेटाबेस से प्रॉडक्ट की जानकारी हासिल की जा सकती है.

productInput संसाधन, किसी प्रॉडक्ट के लिए सबमिट किए गए इनपुट डेटा को दिखाता है. इसमें ऐसे तरीके भी दिए गए हैं जिनकी मदद से, प्रॉडक्ट की जानकारी को एक बार में एक या कई प्रॉडक्ट के लिए अपडेट या मिटाया जा सकता है. इसके लिए, बैच मोड का इस्तेमाल किया जाता है. productInput रिसॉर्स में ये फ़ील्ड होने चाहिए:

  • channel: प्रॉडक्ट का चैनल.
  • offerId: प्रॉडक्ट का यूनीक आइडेंटिफ़ायर.
  • contentLanguage: प्रॉडक्ट के लिए, दो अक्षरों वाला ISO 639-1 भाषा कोड.
  • feedLabel: यह एक ऐसा लेबल है जिसकी मदद से, प्रॉडक्ट की कैटगरी तय की जा सकती है और उन्हें पहचाना जा सकता है. इसमें ज़्यादा से ज़्यादा 20 वर्ण इस्तेमाल किए जा सकते हैं. साथ ही, A-Z, 0-9, हाइफ़न, और अंडरस्कोर जैसे वर्ण इस्तेमाल किए जा सकते हैं. फ़ीड के लेबल में कोई स्पेस नहीं होना चाहिए. ज़्यादा जानकारी के लिए, फ़ीड लेबल का इस्तेमाल करना लेख पढ़ें.

अपने खाते में प्रॉडक्ट इनपुट अपलोड करना

अपने खाते में प्रॉडक्ट इनपुट अपलोड करने के लिए, accounts.productInputs.insert तरीके का इस्तेमाल करें. आपको प्राइमरी या पूरक डेटा सोर्स का यूनीक आइडेंटिफ़ायर देना होगा.

यहां दिए गए अनुरोध के सैंपल में बताया गया है कि अपने Merchant Center खाते में प्रॉडक्ट इनपुट अपलोड करने के लिए, accounts.productInputs.insert तरीके का इस्तेमाल कैसे किया जा सकता है. इस अनुरोध से, शिपिंग के लिए खरीदार से लिया जाने वाला शुल्क और इलाका सेट होता है. साथ ही, मैन्युफ़ैक्चरिंग की तारीख और साइज़ जैसे कस्टम एट्रिब्यूट भी सेट होते हैं.

POST https://merchantapi.googleapis.com/products/v1beta/accounts/{ACCOUNT_ID}/productInputs:insert?dataSource={DATASOURCE}

{
  "name": "{PRODUCT_TITLE}",
  "versionNumber": {VERSION_NUMBER},
  "contentLanguage": "{CONTENT_LANGUAGE}",
  "feedLabel": "{FEED_LABEL}",
  "offerId": "{OFFER_ID}",
  "channel": "ONLINE",
  "attributes": {
    "availability": "in stock",
    "imageLink": "{IMAGE_LINK}",
    "link": "{PRODUCT_LINK}",
    "brand": "{BRAND_NAME}",
    "price": {
      "currencyCode": "{CURRENCY_CODE}",
      "amountMicros": {PRICE}
    },
    "color": "red",
    "productWeight": {
      "value": 320,
      "unit": "g"
    },
    "adult": false,
    "shipping": [
      {
        "country": "GB",
        "price": {
          "amountMicros": {SHIPPING_COST},
          "currencyCode": "{CURRENCY_CODE_SHIPPING}"
        },
        "postalCode": "{SHIPPING_POSTALCODE}",
        "service": "",
        "region": "{SHIPPING_REGION}",
        "maxHandlingTime": "{MAX_HANDLING_TIME}",
        "minHandlingTime": "{MIN_HANDLING_TIME}",
        "maxTransitTime": "{MAX_TRANSIT_TIME}",
        "minTransitTime": "{MIN_TRANSIT_TIME}"
      }
    ],
    "gender": "Female"
  },
  "customAttributes": [
    {
      "name": "size",
      "value": "Large"
    },
    {
      "name": "Date of Manufacturing",
      "value": "2024-05-05"
    }
  ]
}

इनकी जगह ये डालें:

  • {ACCOUNT_ID}: आपके Merchant Center खाते का यूनीक आइडेंटिफ़ायर.
  • {DATASOURCE}: डेटा सोर्स का यूनीक आइडेंटिफ़ायर. यह accounts/{ACCOUNT_ID}/dataSources/{DATASOURCE_ID} फ़ॉर्मैट में होना चाहिए.
  • {PRODUCT_TITLE}: प्रॉडक्ट का नाम.
  • {VERSION_NUMBER}: प्रॉडक्ट का वर्शन नंबर. ज़रूरी नहीं.
  • {CONTENT_LANGUAGE}: प्रॉडक्ट के लिए, दो अक्षरों वाला ISO 639-1 भाषा कोड. ज़रूरी है.
  • {FEED_LABEL}: यह एक ऐसा लेबल है जिसकी मदद से, प्रॉडक्ट की कैटगरी तय की जा सकती है और उन्हें पहचाना जा सकता है. इसमें ज़्यादा से ज़्यादा 20 वर्ण इस्तेमाल किए जा सकते हैं. साथ ही, A-Z, 0-9, हाइफ़न, और अंडरस्कोर का इस्तेमाल किया जा सकता है. फ़ीड लेबल में कोई स्पेस नहीं होना चाहिए.
  • {OFFER_ID}: प्रॉडक्ट का यूनीक आइडेंटिफ़ायर. ज़रूरी है.
  • {IMAGE_LINK}: आपकी वेबसाइट पर मौजूद प्रॉडक्ट की इमेज का लिंक. ज़रूरी नहीं.
  • {PRODUCT_LINK}: आपकी वेबसाइट पर मौजूद प्रॉडक्ट का लिंक. ज़रूरी नहीं.
  • {CURRENCY_CODE}: ISO 4217 के मुताबिक, तीन अक्षरों वाले संक्षिप्त नाम का इस्तेमाल करके कीमत की मुद्रा. ज़रूरी नहीं.
  • {PRICE}: प्रॉडक्ट की कीमत, माइक्रो में संख्या के तौर पर दिखाई जाती है. ज़रूरी नहीं.
  • {SHIPPING_COST}: शिपिंग के लिए तय की गई कीमत को संख्या के तौर पर दिखाया गया है. ज़रूरी नहीं.
  • {SHIPPING_POSTALCODE}: पिन कोड की वह रेंज जहां शिपिंग की दर लागू होती है. ज़रूरी नहीं.
  • {MAX_HANDLING_TIME}: ऑर्डर मिलने और उसे शिप करने के बीच, कामकाजी दिनों में लगने वाला ज़्यादा से ज़्यादा समय. ज़रूरी नहीं.
  • {MIN_HANDLING_TIME}: ऑर्डर मिलने और उसे शिप करने के बीच, कामकाजी दिनों में लगने वाला कम से कम समय. वैल्यू 0 का मतलब है कि ऑर्डर मिलने के दिन ही डिलीवर किया जाता है. ज़रूरी नहीं.
  • {MAX_TRANSIT_TIME}: ऑर्डर भेजने और डिलीवरी करने के बीच, कामकाजी दिनों में लगने वाला ज़्यादा से ज़्यादा समय. ज़रूरी नहीं.
  • {MIN_TRANSIT_TIME}: ऑर्डर भेजने और डिलीवर होने के बीच, कामकाजी दिनों में लगने वाला कम से कम समय. वैल्यू 0 का मतलब है कि ऑर्डर शिप होने के दिन ही डिलीवर हो जाता है. ज़रूरी नहीं.

अनुरोध पूरा होने पर, आपको यह जवाब दिखता है:

{
  "name": "{PRODUCT_NAME}",
  "product": "{PRODUCT_ID}",
  "channel": "ONLINE",
  "offerId": "{OFFER_ID}",
  "contentLanguage": "{CONTENT_LANGUAGE}",
  "feedLabel": "{FEED_LABEL}",
  "versionNumber": "{VERSION_NUMBER}",
  "attributes": {
    "link": "{PRODUCT_LINK}",
    "imageLink": "{IMAGE_LINK}",
    "adult": false,
    "availability": "in stock",
    "brand": "{BRAND_NAME}",
    "color": "red",
    "gender": "Female",
    "price": {
      "amountMicros": "{PRICE}",
      "currencyCode": "{CURRENCY_CODE}"
    },
    "shipping": [
      {
        "price": {
          "amountMicros": "{SHIPPING_COST}",
          "currencyCode": "{CURRENCY_CODE}"
        },
        "country": "{SHIPPING_COUNTRY}",
        "region": "{SHIPPING_REGION}",
        "postalCode": "{SHIPPING_POSTALCODE}",
        "minHandlingTime": "{MIN_HANDLING_TIME}",
        "maxHandlingTime": "{MAX_HANDLING_TIME}",
        "minTransitTime": "{MIN_TRANSIT_TIME}",
        "maxTransitTime": "{MAX_TRANSIT_TIME}"
      }
    ],
    "productWeight": {
      "value": 320,
      "unit": "g"
    }
  },
  "customAttributes": [
    {
      "name": "Size",
      "value": "Large"
    },
    {
      "name": "Date of Manufacturing",
      "value": "2024-05-05"
    }
  ]
}

Merchant Center खाते में प्रॉडक्ट जोड़ने के लिए, यहां दिए गए सैंपल में दिखाए गए तरीके का इस्तेमाल किया जा सकता है. इसके लिए, google.shopping.merchant.accounts.v1beta.InsertProductInputSample का इस्तेमाल करें.

Java

import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.products.v1beta.Attributes;
import com.google.shopping.merchant.products.v1beta.InsertProductInputRequest;
import com.google.shopping.merchant.products.v1beta.ProductInput;
import com.google.shopping.merchant.products.v1beta.ProductInputsServiceClient;
import com.google.shopping.merchant.products.v1beta.ProductInputsServiceSettings;
import com.google.shopping.merchant.products.v1beta.Shipping;
import com.google.shopping.type.Channel.ChannelEnum;
import com.google.shopping.type.Price;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;

/** This class demonstrates how to insert a product input */
public class InsertProductInputSample {

  private static String getParent(String accountId) {
    return String.format("accounts/%s", accountId);
  }

  public static void insertProductInput(Config config, String dataSource) throws Exception {

    // Obtains OAuth token based on the user's configuration.
    GoogleCredentials credential = new Authenticator().authenticate();

    // Creates service settings using the credentials retrieved above.
    ProductInputsServiceSettings productInputsServiceSettings =
        ProductInputsServiceSettings.newBuilder()
            .setCredentialsProvider(FixedCredentialsProvider.create(credential))
            .build();

    // Creates parent to identify where to insert the product.
    String parent = getParent(config.getAccountId().toString());

    // Calls the API and catches and prints any network failures/errors.
    try (ProductInputsServiceClient productInputsServiceClient =
        ProductInputsServiceClient.create(productInputsServiceSettings)) {

      // Price to be used for shipping ($33.45).
      Price price = Price.newBuilder().setAmountMicros(33_450_000).setCurrencyCode("USD").build();

      Shipping shipping =
          Shipping.newBuilder()
              .setPrice(price)
              .setCountry("GB")
              .setService("1st class post")
              .build();

      Shipping shipping2 =
          Shipping.newBuilder()
              .setPrice(price)
              .setCountry("FR")
              .setService("1st class post")
              .build();

      Attributes attributes =
          Attributes.newBuilder()
              .setTitle("A Tale of Two Cities")
              .setDescription("A classic novel about the French Revolution")
              .setLink("https://exampleWebsite.com/tale-of-two-cities.html")
              .setImageLink("https://exampleWebsite.com/tale-of-two-cities.jpg")
              .setAvailability("in stock")
              .setCondition("new")
              .setGoogleProductCategory("Media > Books")
              .setGtin(0, "9780007350896")
              .addShipping(shipping)
              .addShipping(shipping2)
              .build();

      // The datasource can be either a primary or supplemental datasource.
      InsertProductInputRequest request =
          InsertProductInputRequest.newBuilder()
              .setParent(parent)
              // You can only insert products into datasource types of Input "API" and "FILE", and
              // of Type "Primary" or "Supplemental."
              // This field takes the `name` field of the datasource.
              .setDataSource(dataSource)
              // If this product is already owned by another datasource, when re-inserting, the
              // new datasource will take ownership of the product.
              .setProductInput(
                  ProductInput.newBuilder()
                      .setChannel(ChannelEnum.ONLINE)
                      .setContentLanguage("en")
                      .setFeedLabel("label")
                      .setOfferId("sku123")
                      .setAttributes(attributes)
                      .build())
              .build();

      System.out.println("Sending insert ProductInput request");
      ProductInput response = productInputsServiceClient.insertProductInput(request);
      System.out.println("Inserted ProductInput Name below");
      // The last part of the product name will be the product ID assigned to a product by Google.
      // Product ID has the format `channel~contentLanguage~feedLabel~offerId`
      System.out.println(response.getName());
      System.out.println("Inserted Product Name below");
      System.out.println(response.getProduct());
    } catch (Exception e) {
      System.out.println(e);
    }
  }

  public static void main(String[] args) throws Exception {
    Config config = Config.load();
    // Identifies the data source that will own the product input.
    String dataSource = "accounts/" + config.getAccountId() + "/dataSources/{INSERT_DATASOURCE_ID}";

    insertProductInput(config, dataSource);
  }
}

अपने खाते से प्रोसेस किया गया प्रॉडक्ट वापस पाना

अपने खाते से प्रोसेस किए गए प्रॉडक्ट को वापस पाने के लिए, accounts.products.get तरीके का इस्तेमाल करें. प्रॉडक्ट डालने के बाद, उसे प्रोसेस होने में कुछ मिनट लग सकते हैं.

GET https://merchantapi.googleapis.com/products/v1beta/accounts/{ACCOUNT_ID}/products/{PRODUCT_NAME}

{PRODUCT_NAME} को उस प्रॉडक्ट इनपुट रिसॉर्स के नाम से बदलें जिसे आपको मिटाना है. उदाहरण के लिए, online~en~US~sku123.

प्रोसेस किए गए प्रॉडक्ट का नाम, accounts.productInputs.insert के रिस्पॉन्स में मौजूद product फ़ील्ड से देखा जा सकता है.

किसी Merchant Center खाते के लिए एक प्रॉडक्ट को वापस पाने के लिए, यहां दिए गए सैंपल में दिखाए गए तरीके के मुताबिक, google.shopping.merchant.accounts.v1beta.GetProductRequest का इस्तेमाल किया जा सकता है.

Java

import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.products.v1beta.GetProductRequest;
import com.google.shopping.merchant.products.v1beta.Product;
import com.google.shopping.merchant.products.v1beta.ProductsServiceClient;
import com.google.shopping.merchant.products.v1beta.ProductsServiceSettings;
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 {

  public static void getProduct(Config config, String product) 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}
      GetProductRequest request = GetProductRequest.newBuilder().setName(product).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();
    // 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 product = "accounts/{datasource}/products/{productId}";

    getProduct(config, product);
  }
}

अपने खाते से प्रॉडक्ट इनपुट मिटाना

अपने खाते से प्रॉडक्ट इनपुट मिटाने के लिए, accounts.productInputs.delete का तरीका अपनाएं. Merchant Center के प्रॉडक्ट एपीआई का इस्तेमाल करके किसी प्रॉडक्ट को मिटाने के लिए, आपको उस प्राइमरी या सप्लीमेंटल डेटा सोर्स का यूनीक आइडेंटिफ़ायर देना होगा जिससे प्रॉडक्ट जुड़ा है.

यहां दिए गए अनुरोध में बताया गया है कि प्रॉडक्ट इनपुट मिटाने के लिए, accounts.productInputs.delete तरीका कैसे इस्तेमाल किया जा सकता है:

DELETE https://merchantapi.googleapis.com/products/v1beta/accounts/{ACCOUNT_ID}/productInputs/{PRODUCT_NAME}?dataSource=accounts/{ACCOUNT_ID}/dataSources/{DATASOURCE_ID}

{PRODUCT_NAME} को उस प्रॉडक्ट इनपुट रिसॉर्स के नाम से बदलें जिसे आपको मिटाना है. उदाहरण के लिए, online~en~US~sku123.

किसी Merchant Center खाते के लिए प्रॉडक्ट मिटाने के लिए, यहां दिए गए सैंपल में दिखाए गए तरीके का इस्तेमाल किया जा सकता है.google.shopping.merchant.accounts.v1beta.DeleteProductInputRequest

Java

import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.products.v1beta.DeleteProductInputRequest;
import com.google.shopping.merchant.products.v1beta.ProductInputName;
import com.google.shopping.merchant.products.v1beta.ProductInputsServiceClient;
import com.google.shopping.merchant.products.v1beta.ProductInputsServiceSettings;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;

/** This class demonstrates how to delete a product for a given Merchant Center account */
public class DeleteProductInputSample {

  public static void deleteProductInput(Config config, String productId, String dataSource)
      throws Exception {

    // Obtains OAuth token based on the user's configuration.
    GoogleCredentials credential = new Authenticator().authenticate();

    // Creates service settings using the credentials retrieved above.
    ProductInputsServiceSettings productInputsServiceSettings =
        ProductInputsServiceSettings.newBuilder()
            .setCredentialsProvider(FixedCredentialsProvider.create(credential))
            .build();

    // Creates product name to identify product.
    String name =
        ProductInputName.newBuilder()
            .setAccount(config.getAccountId().toString())
            .setProductinput(productId)
            .build()
            .toString();

    // Calls the API and catches and prints any network failures/errors.
    try (ProductInputsServiceClient productInputsServiceClient =
        ProductInputsServiceClient.create(productInputsServiceSettings)) {
      DeleteProductInputRequest request =
          DeleteProductInputRequest.newBuilder().setName(name).setDataSource(dataSource).build();

      System.out.println("Sending deleteProductInput request");
      productInputsServiceClient.deleteProductInput(request); // no response returned on success
      System.out.println(
          "Delete successful, note that it may take a few minutes for the delete to update in"
              + " the system. If you make a products.get or products.list request before a few"
              + " minutes have passed, the old product data may be returned.");
    } catch (Exception e) {
      System.out.println(e);
    }
  }

  public static void main(String[] args) throws Exception {
    Config config = Config.load();
    // An ID assigned to a product by Google. In the format
    // channel~contentLanguage~feedLabel~offerId
    String productId = "online~en~label~sku123";

    // The name of the dataSource from which to delete the product. If it is a primary feed, this
    // will delete the product completely. If it's a supplemental feed, it will only delete the
    // product information from that feed, but the product will still be available from the primary
    // feed.
    String dataSource = "accounts/{account}/dataSources/{dataSource}";

    deleteProductInput(config, productId, dataSource);
  }
}

अपने खाते के प्रॉडक्ट की सूची बनाना

अपने खाते में प्रोसेस किए गए प्रॉडक्ट की सूची बनाने के लिए, accounts.products.list इस तरीके का इस्तेमाल करें, जैसा कि नीचे दिए गए अनुरोध में दिखाया गया है.

GET https://merchantapi.googleapis.com/products/v1beta/accounts/{ACCOUNT_ID}/products

किसी Merchant Center खाते के लिए प्रॉडक्ट लिस्ट करने के लिए, यहां दिए गए सैंपल में दिखाए गए तरीके का इस्तेमाल किया जा सकता है.google.shopping.merchant.accounts.v1beta.ListProductsRequest

Java

import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.products.v1beta.ListProductsRequest;
import com.google.shopping.merchant.products.v1beta.Product;
import com.google.shopping.merchant.products.v1beta.ProductsServiceClient;
import com.google.shopping.merchant.products.v1beta.ProductsServiceClient.ListProductsPagedResponse;
import com.google.shopping.merchant.products.v1beta.ProductsServiceSettings;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;

/** This class demonstrates how to list all the products for a given merchant center account */
public class ListProductsSample {

  private static String getParent(String accountId) {
    return String.format("accounts/%s", accountId);
  }

  public static void listProducts(Config config) 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();

    // Creates parent to identify the account from which to list all products.
    String parent = getParent(config.getAccountId().toString());

    // Calls the API and catches and prints any network failures/errors.
    try (ProductsServiceClient productsServiceClient =
        ProductsServiceClient.create(productsServiceSettings)) {

      // The parent has the format: accounts/{account}
      ListProductsRequest request = ListProductsRequest.newBuilder().setParent(parent).build();

      System.out.println("Sending list products request:");
      ListProductsPagedResponse response = productsServiceClient.listProducts(request);

      int count = 0;

      // Iterates over all rows in all pages and prints the datasource in each row.
      // Automatically uses the `nextPageToken` if returned to fetch all pages of data.
      for (Product product : response.iterateAll()) {

        System.out.println(product); // The product includes the `productStatus` field
        // That shows approval and disapproval information.

        count++;
      }
      System.out.print("The following count of products were returned: ");
      System.out.println(count);
    } catch (Exception e) {
      System.out.println("An error has occured: ");
      System.out.println(e);
    }
  }

  public static void main(String[] args) throws Exception {
    Config config = Config.load();
    listProducts(config);
  }
}