अलग-अलग तरह के डेटा सोर्स मैनेज करना

Merchant API, कई तरह के डेटा सोर्स और इनपुट के तरीकों के साथ काम करता है. इससे, आपके कारोबार की ज़रूरतों के हिसाब से प्रॉडक्ट से जुड़ी जानकारी मिलती है. डेटा सोर्स में अलग-अलग तरह का डेटा हो सकता है:

  • प्रॉडक्ट
  • इन्वेंट्री
  • प्रमोशन
  • समीक्षा

डेटा सोर्स को कई तरीकों से कॉन्फ़िगर किया जा सकता है. इनमें ये तरीके शामिल हैं:

  • एपीआई कॉल
  • फ़ाइल अपलोड करना
  • Autofeed

डेटा सोर्स सब-एपीआई (उदाहरण के लिए, प्रॉडक्ट या प्रमोशन) के ज़रिए मैनेज किए जा सकने वाले कुछ डेटा सोर्स टाइप को, काम करने वाले कई इनपुट तरीकों (एपीआई, फ़ाइल अपलोड या फ़ाइल फ़ेच) के साथ जोड़ा जा सकता है. उदाहरण के लिए, प्रॉडक्ट का प्राइमरी डेटा सोर्स इनमें से कोई भी हो सकता है:

  • एपीआई फ़ीड
  • फ़ेच की गई फ़ाइल का फ़ीड
  • अपलोड की गई फ़ाइल का फ़ीड
  • ऑटोफ़ीड

इस गाइड में, अलग-अलग तरह के डेटा और इनपुट के तरीकों वाले डेटा सोर्स को मैनेज करने के उदाहरण दिए गए हैं.

ध्यान देने वाली खास बातें

कुछ डेटा सोर्स टाइप के लिए, इन खास बातों का ध्यान रखें.

  • रीड-ओनली डेटा सोर्स: डेटा सोर्स के कुछ टाइप, डेटा सोर्स सब-एपीआई के ज़रिए रीड-ओनली होते हैं. इसका मतलब है कि आपके पास उन्हें सूची में शामिल करने और उनकी जानकारी देखने का विकल्प है. हालांकि, इस एपीआई का इस्तेमाल करके उन्हें न तो बनाया जा सकता है, न ही अपडेट किया जा सकता है और न ही मिटाया जा सकता है. इनमें ये शामिल हैं:
    • ऐसे डेटा सोर्स जिनमें मौजूद प्रॉडक्ट को सीधे तौर पर Merchant Center के यूज़र इंटरफ़ेस (यूआई) में मैनेज किया जाता है (इनपुट टाइप UI).
    • ऑटोफ़ीड (इनपुट टाइप AUTOFEED). डेटा सोर्स सब-एपीआई में, ऑटोफ़ीड सिर्फ़ पढ़ने के लिए होते हैं. हालांकि, खाते के सब-एपीआई में autofeedSettings तरीकों का इस्तेमाल करके, अपने खाते के लिए ऑटोफ़ीड की सुविधा को चालू या बंद किया जा सकता है. ज़्यादा जानकारी के लिए, अपने-आप फ़ीड होने की सेटिंग कॉन्फ़िगर करना सेक्शन देखें.
  • फ़ीड के नियम: डेटा सोर्स सब-एपीआई, मुख्य रूप से पूरक डेटा सोर्स को प्राइमरी डेटा सोर्स से लिंक करने के लिए, डिफ़ॉल्ट फ़ीड के नियमों के साथ काम करता है. इस एपीआई में, सीधे तौर पर जटिल कस्टम नियम बनाने और मैनेज करने की सुविधा उपलब्ध नहीं है. डिफ़ॉल्ट नियम में, पूरक डेटा सोर्स के क्रम को मैनेज किया जा सकता है. इससे यह तय किया जा सकता है कि प्राइमरी सोर्स और पूरक सोर्स के एट्रिब्यूट किस क्रम में जोड़े जाएं.

शेड्यूल की गई फ़ाइल फ़ेच करने की सुविधा के साथ, स्थानीय इन्वेंट्री का डेटा सोर्स सेट अप करना

आपके पास स्थानीय इन्वेंट्री का ऐसा डेटा सोर्स बनाने का विकल्प है जो शेड्यूल के हिसाब से, किसी तय यूआरएल से फ़ाइल को अपने-आप फ़ेच करता है. क्षेत्रीय इन्वेंट्री के लिए मिलता-जुलता डेटा सोर्स बनाने के लिए, अनुरोध के मुख्य हिस्से में localInventoryDataSource फ़ील्ड को regionalInventoryDataSource से बदलें.

डेटा सोर्स बनाने के लिए, dataSources.create तरीका इस्तेमाल करें और कॉन्फ़िगर किए गए fetchSettings के साथ fileInput ऑब्जेक्ट दें.

POST https://merchantapi.googleapis.com/datasources/v1beta/accounts/{ACCOUNT_ID}/dataSources
{
  "displayName": "My Scheduled Local Inventory Feed",
  "localInventoryDataSource": {
    "feedLabel": "US_Stores",
    "contentLanguage": "en"
  },
  "fileInput": {
    "fetchSettings": {
      "enabled": true,
      "timeOfDay": {
        "hours": 23
      },
      "timeZone": "America/New_York",
      "frequency": "FREQUENCY_DAILY",
      "fetchUri": "https://www.example.com/inventory/local_inventory_feed.csv"
    }
  }
}

अनुरोध पूरा होने पर, बनाया गया DataSource संसाधन दिखता है.

{
  "name": "accounts/{ACCOUNT_ID}/dataSources/{DATASOURCE_ID}",
  "dataSourceId": "{DATASOURCE_ID}",
  "displayName": "My Scheduled Local Inventory Feed",
  "localInventoryDataSource": {
    "feedLabel": "US_Stores",
    "contentLanguage": "en"
  },
  "input": "FILE",
  "fileInput": {
    "fetchSettings": {
      "enabled": true,
      "timeOfDay": {
        "hours": 23
      },
      "timeZone": "America/New_York",
      "frequency": "FREQUENCY_DAILY",
      "fetchUri": "https://www.example.com/inventory/local_inventory_feed.csv"
    },
    "fileInputType": "FETCH"
  }
}

यहां दिए गए कोड सैंपल में, शेड्यूल की गई फ़ेचिंग की सुविधा के साथ स्थानीय इन्वेंट्री डेटा सोर्स बनाने का तरीका बताया गया है.

Java

import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.datasources.v1beta.CreateDataSourceRequest;
import com.google.shopping.merchant.datasources.v1beta.DataSource;
import com.google.shopping.merchant.datasources.v1beta.DataSourcesServiceClient;
import com.google.shopping.merchant.datasources.v1beta.DataSourcesServiceSettings;
import com.google.shopping.merchant.datasources.v1beta.FileInput;
import com.google.shopping.merchant.datasources.v1beta.LocalInventoryDataSource;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;

/** This class demonstrates how to create a local inventory datasource */
public class CreateFileLocalInventoryDataSourceSample {

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

  private static FileInput setFileInput() {
    // If FetchSettings are not set, then this will be an `UPLOAD` file type
    // that you must manually upload via the Merchant Center UI.
    return FileInput.newBuilder()
        // FileName is required for `UPLOAD` fileInput type.
        .setFileName("British T-shirts Local Inventory Data")
        .build();
  }

  public static String createDataSource(Config config, String displayName, FileInput fileInput)
      throws Exception {
    GoogleCredentials credential = new Authenticator().authenticate();

    DataSourcesServiceSettings dataSourcesServiceSettings =
        DataSourcesServiceSettings.newBuilder()
            .setCredentialsProvider(FixedCredentialsProvider.create(credential))
            .build();

    String parent = getParent(config.getAccountId().toString());

    // LocalInventoryDataSources can only be created for a specific `feedLabel` and
    // `contentLanguage` combination.
    LocalInventoryDataSource localInventoryDataSource =
        LocalInventoryDataSource.newBuilder().setContentLanguage("en").setFeedLabel("GB").build();

    try (DataSourcesServiceClient dataSourcesServiceClient =
        DataSourcesServiceClient.create(dataSourcesServiceSettings)) {

      CreateDataSourceRequest request =
          CreateDataSourceRequest.newBuilder()
              .setParent(parent)
              .setDataSource(
                  DataSource.newBuilder()
                      .setDisplayName(displayName)
                      .setLocalInventoryDataSource(localInventoryDataSource)
                      .setFileInput(fileInput)
                      .build())
              .build();

      System.out.println("Sending Create Local Inventory DataSource request");
      DataSource response = dataSourcesServiceClient.createDataSource(request);
      System.out.println("Inserted DataSource Name below");
      System.out.println(response.getName());
      return response.getName();
    } catch (Exception e) {
      System.out.println(e);
      System.exit(1);
      return null;
    }
  }

  public static void main(String[] args) throws Exception {
    Config config = Config.load();
    // The displayed datasource name in the Merchant Center UI.
    String displayName = "British Local Inventory File";

    // The file input data that this datasource will receive.
    FileInput fileInput = setFileInput();

    createDataSource(config, displayName, fileInput);
  }
}

PHP

use Google\ApiCore\ApiException;
use Google\Shopping\Merchant\DataSources\V1beta\Client\DataSourcesServiceClient;
use Google\Shopping\Merchant\DataSources\V1beta\CreateDataSourceRequest;
use Google\Shopping\Merchant\DataSources\V1beta\DataSource;
use Google\Shopping\Merchant\DataSources\V1beta\FileInput;
use Google\Shopping\Merchant\DataSources\V1beta\LocalInventoryDataSource;

/**
 * This class demonstrates how to create a local inventory datasource with a 
 * file input.
 */
class CreateFileLocalInventoryDataSourceSample
{

    private static function getFileInput(): FileInput
    {
        // If FetchSettings is not set, then this will be an `UPLOAD` file type
        // that you must manually upload via the Merchant Center UI.
        return (new FileInput())
            // FileName is required for `UPLOAD` fileInput type.
            ->setFileName('British T-shirts Local Inventory Data');
    }

    public function createDataSource(string $merchantId, string $displayName, FileInput $fileInput): void
    {
        // Gets the OAuth credentials to make the request.
        $credentials = Authentication::useServiceAccountOrTokenFile();

        // Creates options config containing credentials for the client to use.
        $options = ['credentials' => $credentials];

        // Creates a client.
        $dataSourcesServiceClient = new DataSourcesServiceClient($options);

        $parent = sprintf('accounts/%s', $merchantId);

        // LocalInventoryDataSources can only be created for a specific `feedLabel` and
        // `contentLanguage` combination.
        $localInventoryDataSource =
            (new LocalInventoryDataSource())
                ->setContentLanguage('en')
                ->setFeedLabel('GB');

        try {
            // Prepare the request message.
            $request = (new CreateDataSourceRequest())
                ->setParent($parent)
                ->setDataSource(
                    (new DataSource())
                        ->setDisplayName($displayName)
                        ->setLocalInventoryDataSource($localInventoryDataSource)
                        ->setFileInput($fileInput)
                );

            print('Sending Create Local Inventory DataSource request' . PHP_EOL);
            $response = $dataSourcesServiceClient->createDataSource($request);
            print('Inserted DataSource Name below' . PHP_EOL);
            print($response->getName() . PHP_EOL);
        } catch (ApiException $ex) {
            printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
        }
    }

    // Helper to execute the sample.
    function callSample(): void
    {
        $config = Config::generateConfig();
        // The Merchant Center Account ID.
        $merchantId = $config['accountId'];

        // The displayed datasource name in the Merchant Center UI.
        $displayName = 'British Primary Inventory File';

        $fileInput = self::getFileInput();

        $this->createDataSource($merchantId, $displayName, $fileInput);
    }

}

$sample = new CreateFileLocalInventoryDataSourceSample();
$sample->callSample();

Python

from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.shopping.merchant_datasources_v1beta import CreateDataSourceRequest
from google.shopping.merchant_datasources_v1beta import DataSource
from google.shopping.merchant_datasources_v1beta import DataSourcesServiceClient
from google.shopping.merchant_datasources_v1beta import FileInput
from google.shopping.merchant_datasources_v1beta import LocalInventoryDataSource

_ACCOUNT = configuration.Configuration().read_merchant_info()
_PARENT = f"accounts/{_ACCOUNT}"


def create_file_local_inventory_data_source():
  """Creates a `DataSource` resource."""

  # Gets OAuth Credentials.
  credentials = generate_user_credentials.main()

  # Creates a client.
  client = DataSourcesServiceClient(credentials=credentials)

  # If FetchSettings are not set, then this will be an `UPLOAD` file type
  # that you must manually upload via the Merchant Center UI or via SFTP.
  file_input = FileInput()
  file_input.file_name = "British T-shirts Local Inventory Data.txt"

  # Creates a SupplementalProductDataSource.
  local_inventory_datasource = LocalInventoryDataSource()
  # LocalInventoryDataSources can only be created for a specific
  # `feedLabel` and `contentLanguage` combination.
  local_inventory_datasource.content_language = "en"
  local_inventory_datasource.feed_label = "GB"

  # Creates a DataSource and populates its attributes.
  data_source = DataSource()
  data_source.display_name = "Example Local Inventory DataSource"
  data_source.local_inventory_data_source = local_inventory_datasource
  data_source.file_input = file_input

  # Creates the request.
  request = CreateDataSourceRequest(parent=_PARENT, data_source=data_source)

  # Makes the request and catches and prints any error messages.
  try:
    response = client.create_data_source(request=request)
    print(f"DataSource successfully created: {response}")
  except RuntimeError as e:
    print("DataSource creation failed")
    print(e)


if __name__ == "__main__":
  create_file_local_inventory_data_source()

cURL

curl -X POST \
"https://merchantapi.googleapis.com/datasources/v1beta/accounts/{ACCOUNT_ID}/dataSources" \
-H "Authorization: Bearer <API_TOKEN>" \
-H "Content-Type: application/json" \
-d '{
      "displayName": "My Scheduled Local Inventory Feed",
      "localInventoryDataSource": {
        "feedLabel": "US_Stores",
        "contentLanguage": "en"
      },
      "fileInput": {
        "fetchSettings": {
          "enabled": true,
          "timeOfDay": {
            "hours": 23
          },
          "timeZone": "America/New_York",
          "frequency": "FREQUENCY_DAILY",
          "fetchUri": "https://www.example.com/inventory/local_inventory_feed.csv"
        }
      }
    }'

एपीआई का इस्तेमाल करके, प्रमोशन की जानकारी वाला डेटा सोर्स सेट अप करना

प्रमोशन के डेटा सोर्स की मदद से, अपने प्रॉडक्ट के लिए प्रमोशनल ऑफ़र सबमिट किए जा सकते हैं. आपके पास अपने प्रमोशन के लिए, एपीआई पर आधारित डेटा सोर्स बनाने का विकल्प है. इससे, आपको फ़ाइलों को मैनेज किए बिना, सीधे तौर पर प्रमोशन का डेटा भेजने की सुविधा मिलती है.

dataSources.create वाला तरीका इस्तेमाल करें और promotionDataSource की वैल्यू डालें. एपीआई फ़ीड के लिए, fileInput फ़ील्ड को छोड़ दें.

POST https://merchantapi.googleapis.com/datasources/v1beta/accounts/{ACCOUNT_ID}/dataSources
{
  "displayName": "My API Promotions Source",
  "promotionDataSource": {
    "targetCountry": "US",
    "contentLanguage": "en"
  }
}

अनुरोध पूरा होने पर, नया DataSource संसाधन दिखता है.

{
  "name": "accounts/{ACCOUNT_ID}/dataSources/{DATASOURCE_ID}",
  "dataSourceId": "{DATASOURCE_ID}",
  "displayName": "My API Promotions Source",
  "promotionDataSource": {
    "targetCountry": "US",
    "contentLanguage": "en"
  },
  "input": "API"
}

यहां दिए गए कोड सैंपल से पता चलता है कि एपीआई पर आधारित प्रमोशन डेटा सोर्स कैसे बनाया जाता है.

Java

import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.datasources.v1beta.CreateDataSourceRequest;
import com.google.shopping.merchant.datasources.v1beta.DataSource;
import com.google.shopping.merchant.datasources.v1beta.DataSourcesServiceClient;
import com.google.shopping.merchant.datasources.v1beta.DataSourcesServiceSettings;
import com.google.shopping.merchant.datasources.v1beta.PromotionDataSource;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;

/** This class demonstrates how to create a promotion datasource. */
public class CreatePromotionDataSourceSample {

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

  public static String createDataSource(Config config, String displayName) throws Exception {
    GoogleCredentials credential = new Authenticator().authenticate();

    DataSourcesServiceSettings dataSourcesServiceSettings =
        DataSourcesServiceSettings.newBuilder()
            .setCredentialsProvider(FixedCredentialsProvider.create(credential))
            .build();

    String parent = getParent(config.getAccountId().toString());

    try (DataSourcesServiceClient dataSourcesServiceClient =
        DataSourcesServiceClient.create(dataSourcesServiceSettings)) {

      CreateDataSourceRequest request =
          CreateDataSourceRequest.newBuilder()
              .setParent(parent)
              .setDataSource(
                  DataSource.newBuilder()
                      .setDisplayName(displayName)
                      // PromotionDataSources
                      // can only be created for a specific `targetCountry` and `contentLanguage`
                      // combination.
                      .setPromotionDataSource(
                          PromotionDataSource.newBuilder()
                              .setContentLanguage("en")
                              .setTargetCountry("GB")
                              .build())
                      .build())
              .build();

      System.out.println("Sending Create Promotion DataSource request");
      DataSource response = dataSourcesServiceClient.createDataSource(request);
      System.out.println("Inserted DataSource Name below");
      System.out.println(response.getName());
      return response.getName();
    } catch (Exception e) {
      System.out.println(e);
      System.exit(1);
      return null;
    }
  }

  public static void main(String[] args) throws Exception {
    Config config = Config.load();
    // The displayed datasource name in the Merchant Center UI.
    String displayName = "British Promotions";

    createDataSource(config, displayName);
  }
}

PHP

use Google\ApiCore\ApiException;
use Google\Shopping\Merchant\DataSources\V1beta\Client\DataSourcesServiceClient;
use Google\Shopping\Merchant\DataSources\V1beta\CreateDataSourceRequest;
use Google\Shopping\Merchant\DataSources\V1beta\DataSource;
use Google\Shopping\Merchant\DataSources\V1beta\PromotionDataSource;

/**
 * This class demonstrates how to create a promotion datasource.
 */

class CreatePromotionDataSource
{
    /**
     * Creates a new PromotionDataSource.
     *
     * @param int    $merchantId The Merchant Center account ID.
     * @param string $displayName The displayed datasource name in the Merchant Center UI.
     * @return string The name of the newly created PromotionDataSource.
     */
    function createPromotionDataSourceSample(int $merchantId, string $displayName): string
    {
        // Gets the OAuth credentials to make the request.
        $credentials = Authentication::useServiceAccountOrTokenFile();

        // Creates options config containing credentials for the client to use.
        $options = ['credentials' => $credentials];

        // Creates a client.
        $dataSourcesServiceClient = new DataSourcesServiceClient($options);

        $parent = sprintf('accounts/%s', $merchantId);

        // Creates the data source.
        $dataSource = (new DataSource())
            ->setDisplayName($displayName)
            ->setPromotionDataSource(
                (new PromotionDataSource())
                    ->setContentLanguage('en')
                    ->setTargetCountry('GB')
            );

        // Creates the request.
        $request = (new CreateDataSourceRequest())
            ->setParent($parent)
            ->setDataSource($dataSource);

        // Sends the request to the API.
        try {
            print('Sending Create Promotion DataSource request' . PHP_EOL);
            $response = $dataSourcesServiceClient->createDataSource($request);
            print('Inserted DataSource Name below' . PHP_EOL);
            print($response->getName() . PHP_EOL);
            return $response->getName();
        } catch (ApiException $ex) {
            printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
            return '';
        }
    }

    // Helper to execute the sample.
    public function callSample(): void
    {
        $config = Config::generateConfig();
        // The Merchant Center Account ID.
        $merchantId = $config['accountId'];

        // The displayed datasource name in the Merchant Center UI.
        $displayName = 'British Promotions';

        $this->createPromotionDataSourceSample($merchantId, $displayName);
    }
}

$sample = new CreatePromotionDataSource();
$sample->callSample();

Python

from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.shopping import merchant_datasources_v1beta

_ACCOUNT = configuration.Configuration().read_merchant_info()
_PARENT = f"accounts/{_ACCOUNT}"


def create_promotion_data_source():
  """Creates a `DataSource` resource."""

  # Gets OAuth Credentials.
  credentials = generate_user_credentials.main()

  # Creates a client.
  client = merchant_datasources_v1beta.DataSourcesServiceClient(
      credentials=credentials
  )

  # Creates a PromotionDataSource.
  # PromotionDataSources
  # can only be created for a specific `targetCountry` and `contentLanguage`
  # combination.
  promotion_datasource = merchant_datasources_v1beta.PromotionDataSource()
  promotion_datasource.target_country = "CH"
  promotion_datasource.content_language = "fr"

  # Creates a DataSource and populates its attributes.
  data_source = merchant_datasources_v1beta.DataSource()
  data_source.display_name = "Example DataSource"
  data_source.promotion_data_source = promotion_datasource

  # Creates the request.
  request = merchant_datasources_v1beta.CreateDataSourceRequest(
      parent=_PARENT, data_source=data_source
  )

  # Makes the request and catches and prints any error messages.
  try:
    response = client.create_data_source(request=request)
    print(f"DataSource successfully created: {response}")
  except RuntimeError as e:
    print("DataSource creation failed")
    print(e)


if __name__ == "__main__":
  create_promotion_data_source()

cURL

curl -X POST \
"https://merchantapi.googleapis.com/datasources/v1beta/accounts/{ACCOUNT_ID}/dataSources" \
-H "Authorization: Bearer <API_TOKEN>" \
-H "Content-Type: application/json" \
-d '{
      "displayName": "My API Promotions Source",
      "promotionDataSource": {
        "targetCountry": "US",
        "contentLanguage": "en"
      }
    }'

फ़ाइल अपलोड करने के लिए, प्रॉडक्ट की समीक्षा का डेटा सोर्स बनाना

अपने प्रॉडक्ट के लिए खरीदारों की समीक्षाएं सबमिट करने के लिए, प्रॉडक्ट की समीक्षा के डेटा सोर्स का इस्तेमाल करें. डेटा सोर्स को कॉन्फ़िगर करके, प्रॉडक्ट की समीक्षाओं के लिए मैन्युअल तरीके से अपलोड की गई फ़ाइलों को स्वीकार किया जा सकता है.

dataSources.create वाला तरीका इस्तेमाल करें, productReviewDataSource तय करें, और तय किए गए fileName के साथ fileInput शामिल करें.

POST https://merchantapi.googleapis.com/datasources/v1beta/accounts/{ACCOUNT_ID}/dataSources
{
  "displayName": "My Product Reviews Upload Feed",
  "productReviewDataSource": {},
  "fileInput": {
    "fileName": "product_reviews.xml"
  }
}

अनुरोध पूरा होने पर, नया DataSource संसाधन दिखता है.

{
  "name": "accounts/{ACCOUNT_ID}/dataSources/{DATASOURCE_ID}",
  "dataSourceId": "{DATASOURCE_ID}",
  "displayName": "My Product Reviews Upload Feed",
  "productReviewDataSource": {},
  "input": "FILE",
  "fileInput": {
    "fileName": "product_reviews.xml",
    "fileInputType": "UPLOAD"
  }
}

कारोबारी या कंपनी की समीक्षाओं का डेटा सोर्स बनाने के लिए, इसी तरह के अनुरोध का इस्तेमाल किया जा सकता है. इसके लिए, productReviewDataSource ऑब्जेक्ट को खाली merchantReviewDataSource ऑब्जेक्ट से बदलें.

यहां दिए गए कोड सैंपल में, मैन्युअल तरीके से फ़ाइल अपलोड करने के लिए, प्रॉडक्ट की समीक्षा का डेटा सोर्स बनाने का तरीका बताया गया है.

Java

import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.datasources.v1beta.CreateDataSourceRequest;
import com.google.shopping.merchant.datasources.v1beta.DataSource;
import com.google.shopping.merchant.datasources.v1beta.DataSourcesServiceClient;
import com.google.shopping.merchant.datasources.v1beta.DataSourcesServiceSettings;
import com.google.shopping.merchant.datasources.v1beta.ProductReviewDataSource;
import java.io.IOException;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;

/** This class demonstrates how to create a product review data source. */
public class CreateProductReviewsDataSourceSample {

  private static void createProductReviewsDataSource(String accountId) throws IOException {

    GoogleCredentials credential = new Authenticator().authenticate();

    DataSourcesServiceSettings dataSourcesServiceSettings =
        DataSourcesServiceSettings.newBuilder()
            .setCredentialsProvider(FixedCredentialsProvider.create(credential))
            .build();

    try (DataSourcesServiceClient dataSourcesServiceClient =
        DataSourcesServiceClient.create(dataSourcesServiceSettings)) {
      CreateDataSourceRequest request =
          CreateDataSourceRequest.newBuilder()
              .setParent(String.format("accounts/%s", accountId))
              .setDataSource(
                  DataSource.newBuilder()
                      .setDisplayName("Product Reviews Data Source")
                      .setProductReviewDataSource(ProductReviewDataSource.newBuilder().build())
                      .build())
              .build();

      System.out.println("Creating product reviews data source...");
      DataSource dataSource = dataSourcesServiceClient.createDataSource(request);
      System.out.println(
          String.format("Datasource created successfully: %s", dataSource.getName()));
    } catch (Exception e) {
      System.out.println(e);
      System.exit(1);
    }
  }

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

cURL

curl -X POST \
"https://merchantapi.googleapis.com/datasources/v1beta/accounts/{ACCOUNT_ID}/dataSources" \
-H "Authorization: Bearer <API_TOKEN>" \
-H "Content-Type: application/json" \
-d '{
      "displayName": "My Product Reviews Upload Feed",
      "productReviewDataSource": {},
      "fileInput": {
        "fileName": "product_reviews.xml"
      }
    }'

ऑटोफ़ीड की सेटिंग कॉन्फ़िगर करना

ऑटोफ़ीड, आपकी वेबसाइट के कॉन्टेंट के आधार पर प्रॉडक्ट डेटा अपने-आप बनाते हैं. ऑटोफ़ीड डेटा सोर्स, डेटा सोर्स सब-एपीआई में रीड-ओनली होता है. हालांकि, खाते के सब-एपीआई में autofeedSettings.update का इस्तेमाल करके, अपने खाते के लिए ऑटोफ़ीड की सुविधा को चालू या बंद किया जा सकता है.

इस उदाहरण में, खाते के लिए ऑटोफ़ीड की मदद से प्रॉडक्ट क्रॉल करने की सुविधा चालू की गई है.

PATCH https://merchantapi.googleapis.com/accounts/v1beta/accounts/{ACCOUNT_ID}/autofeedSettings?updateMask=enableProducts
{
  "name": "accounts/{ACCOUNT_ID}/autofeedSettings",
  "enableProducts": true
}

अनुरोध पूरा होने पर, अपडेट किया गया AutofeedSettings रिसॉर्स दिखता है.

{
  "name": "accounts/{ACCOUNT_ID}/autofeedSettings",
  "enableProducts": true,
  "eligible": true
}

नीचे दिए गए कोड सैंपल में, किसी खाते के लिए फ़ीड अपने-आप जुड़ने की सेटिंग चालू करने का तरीका बताया गया है.

Java

import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.protobuf.FieldMask;
import com.google.shopping.merchant.accounts.v1beta.AutofeedSettings;
import com.google.shopping.merchant.accounts.v1beta.AutofeedSettingsName;
import com.google.shopping.merchant.accounts.v1beta.AutofeedSettingsServiceClient;
import com.google.shopping.merchant.accounts.v1beta.AutofeedSettingsServiceSettings;
import com.google.shopping.merchant.accounts.v1beta.UpdateAutofeedSettingsRequest;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;

/** This class demonstrates how to update AutofeedSettings to be enabled. */
public class UpdateAutofeedSettingsSample {

  public static void updateAutofeedSettings(Config config) throws Exception {

    GoogleCredentials credential = new Authenticator().authenticate();

    AutofeedSettingsServiceSettings autofeedSettingsServiceSettings =
        AutofeedSettingsServiceSettings.newBuilder()
            .setCredentialsProvider(FixedCredentialsProvider.create(credential))
            .build();

    // Creates AutofeedSettings name to identify AutofeedSettings.
    String name =
        AutofeedSettingsName.newBuilder()
            .setAccount(config.getAccountId().toString())
            .build()
            .toString();

    // Create AutofeedSettings with the updated fields.
    AutofeedSettings autofeedSettings = AutofeedSettings.newBuilder().setName(name).build();

    FieldMask fieldMask = FieldMask.newBuilder().addPaths("*").build();

    try (AutofeedSettingsServiceClient autofeedSettingsServiceClient =
        AutofeedSettingsServiceClient.create(autofeedSettingsServiceSettings)) {

      UpdateAutofeedSettingsRequest request =
          UpdateAutofeedSettingsRequest.newBuilder()
              .setAutofeedSettings(autofeedSettings)
              .setUpdateMask(fieldMask)
              .build();

      System.out.println("Sending Update AutofeedSettings request");
      AutofeedSettings response = autofeedSettingsServiceClient.updateAutofeedSettings(request);
      System.out.println("Updated AutofeedSettings Name below");
      System.out.println(response.getName());
    } catch (Exception e) {
      System.out.println(e);
    }
  }

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

    updateAutofeedSettings(config);
  }
}

PHP

use Google\ApiCore\ApiException;
use Google\Protobuf\FieldMask;
use Google\Shopping\Merchant\Accounts\V1beta\AutofeedSettings;
use Google\Shopping\Merchant\Accounts\V1beta\Client\AutofeedSettingsServiceClient;
use Google\Shopping\Merchant\Accounts\V1beta\UpdateAutofeedSettingsRequest;

/**
 * This class demonstrates how to update AutofeedSettings to be enabled.
 */
class UpdateAutofeedSettingsSample
{

    /**
     * Update AutofeedSettings to be enabled.
     *
     * @param array $config The configuration data for authentication and account ID.
     * @return void
     */
    public static function updateAutofeedSettingsSample(array $config): void
    {
        // Get OAuth credentials.
        $credentials = Authentication::useServiceAccountOrTokenFile();

        // Create options for the client.
        $options = ['credentials' => $credentials];

        // Create a client.
        $autofeedSettingsServiceClient = new AutofeedSettingsServiceClient($options);

        // Create the AutofeedSettings name.
        $name = "accounts/" . $config['accountId'] . "/autofeedSettings";

        // Create AutofeedSettings object.
        $autofeedSettings = (new AutofeedSettings())
            ->setName($name);

        // Create FieldMask.
        $fieldMask = (new FieldMask())
            ->setPaths(["*"]);

        // Call the API.
        try {
            // Prepare the request.
            $request = (new UpdateAutofeedSettingsRequest())
                ->setAutofeedSettings($autofeedSettings)
                ->setUpdateMask($fieldMask);

            print "Sending Update AutofeedSettings request\n";
            $response = $autofeedSettingsServiceClient->updateAutofeedSettings($request);
            print "Updated AutofeedSettings Name below\n";
            print $response->getName() . "\n";
        } catch (ApiException $e) {
            print $e->getMessage();
        }
    }

    /**
     * Helper to execute the sample.
     *
     * @return void
     */
    public function callSample(): void
    {
        $config = Config::generateConfig();

        self::updateAutofeedSettingsSample($config);
    }
}

// Run the script
$sample = new UpdateAutofeedSettingsSample();
$sample->callSample();

Python

from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.protobuf import field_mask_pb2
from google.shopping.merchant_accounts_v1beta import AutofeedSettings
from google.shopping.merchant_accounts_v1beta import AutofeedSettingsServiceClient
from google.shopping.merchant_accounts_v1beta import UpdateAutofeedSettingsRequest

_ACCOUNT = configuration.Configuration().read_merchant_info()


def update_autofeed_settings():
  """Updates the AutofeedSettings of a Merchant Center account."""

  # Gets OAuth Credentials.
  credentials = generate_user_credentials.main()

  # Creates a client.
  client = AutofeedSettingsServiceClient(credentials=credentials)

  # Creates name to identify the AutofeedSettings.
  name = "accounts/" + _ACCOUNT + "/autofeedSettings"

  # Create AutofeedSettings with the updated fields.
  autofeed_settings = AutofeedSettings(name=name, enable_products=False)

  # Create the field mask.
  field_mask = field_mask_pb2.FieldMask(paths=["enable_products"])

  # Creates the request.
  request = UpdateAutofeedSettingsRequest(
      autofeed_settings=autofeed_settings, update_mask=field_mask
  )

  # Makes the request and catches and prints any error messages.
  try:
    response = client.update_autofeed_settings(request=request)
    print("Updated AutofeedSettings Name below")
    print(response.name)
  except RuntimeError as e:
    print("Update AutofeedSettings request failed")
    print(e)


if __name__ == "__main__":
  update_autofeed_settings()

cURL

curl -X PATCH \
"https://merchantapi.googleapis.com/accounts/v1beta/accounts/{ACCOUNT_ID}/autofeedSettings?updateMask=enableProducts" \
-H "Authorization: Bearer <API_TOKEN>" \
-H "Content-Type: application/json" \
-d '{
      "name": "accounts/{ACCOUNT_ID}/autofeedSettings",
      "enableProducts": true
    }'