আপনার ব্যবসার প্রয়োজনের সাথে সামঞ্জস্য রেখে পণ্য-সম্পর্কিত তথ্য প্রদান করতে মার্চেন্ট API একাধিক ধরণের ডেটা উত্স এবং ইনপুট পদ্ধতি সমর্থন করে। ডেটা উত্সগুলিতে বিভিন্ন ধরণের ডেটা থাকতে পারে:
- পণ্য
- জায়
- প্রচার
- পর্যালোচনা
আপনি একাধিক পদ্ধতি ব্যবহার করে ডেটা উত্স কনফিগার করতে পারেন, যার মধ্যে রয়েছে:
- API কল
- ফাইল আপলোড
- অটোফিড
আপনি একাধিক সমর্থিত ইনপুট পদ্ধতির (API, ফাইল আপলোড, বা ফাইল আনা) সাথে ডেটা সোর্স সাব-এপিআই (উদাহরণস্বরূপ পণ্য বা প্রচার) এর মাধ্যমে পরিচালনাযোগ্য কিছু ডেটা উত্স প্রকারকে একত্রিত করতে পারেন। উদাহরণস্বরূপ, একটি প্রাথমিক পণ্য ডেটা উত্স নিম্নলিখিত যে কোনও একটি হতে পারে:
- একটি API ফিড
- একটি আনা ফাইল ফিড
- একটি আপলোড করা ফাইল ফিড
- একটি অটোফিড
এই নির্দেশিকাটি বিভিন্ন ধরণের ডেটা এবং ইনপুট পদ্ধতি সহ ডেটা উত্সগুলি পরিচালনা করার উদাহরণ প্রদান করে৷
বিশেষ বিবেচনা
কিছু তথ্য উৎসের প্রকারের সাথে নিম্নলিখিত বিশেষ বিবেচনাগুলি বিবেচনা করুন৷
- শুধুমাত্র পঠনযোগ্য ডেটা উৎস : কিছু ডেটা উৎসের ধরন শুধুমাত্র ডেটা সোর্স সাব-এপিআই-এর মাধ্যমে পঠনযোগ্য। এর মানে আপনি তাদের তালিকা করতে এবং তাদের বিশদ বিবরণ দেখতে পারেন, কিন্তু আপনি এই API ব্যবহার করে সেগুলি তৈরি করতে, আপডেট করতে বা মুছতে পারবেন না। এর মধ্যে রয়েছে:
- মার্চেন্ট সেন্টার UI (ইনপুট টাইপ
UI
) তে সরাসরি পরিচালিত পণ্যগুলির সাথে ডেটা উত্স। - অটোফিড (ইনপুট টাইপ
AUTOFEED
)। যদিও অটোফিডগুলি ডেটা উত্স সাব-এপিআই-এর মধ্যে শুধুমাত্র পঠনযোগ্য, আপনি অ্যাকাউন্ট সাব-এপিআই-এautofeedSettings
পদ্ধতিগুলি ব্যবহার করে আপনার অ্যাকাউন্টের জন্য অটোফিড বৈশিষ্ট্যটি সক্ষম বা অক্ষম করতে পারেন৷ আরও তথ্যের জন্য, স্বয়ংক্রিয় ফিড সেটিংস কনফিগার করুন বিভাগ দেখুন।
- মার্চেন্ট সেন্টার UI (ইনপুট টাইপ
- ফিডের নিয়ম : ডেটা সোর্স সাব-এপিআই প্রাথমিকভাবে প্রাথমিক ডেটা সোর্সের সাথে সম্পূরক ডেটা সোর্স লিঙ্ক করার জন্য ডিফল্ট ফিড নিয়ম সমর্থন করে। জটিল কাস্টম নিয়ম তৈরি এবং পরিচালনা এই API এর মধ্যে সরাসরি সমর্থিত নয়। প্রাথমিক উৎস এবং সম্পূরক উৎস থেকে কোন ক্রম বৈশিষ্ট্যগুলি একত্রিত করা হয়েছে তা নির্দিষ্ট করতে আপনি ডিফল্ট নিয়মের মধ্যে পরিপূরক ডেটা উত্সগুলির ক্রম পরিচালনা করতে পারেন৷
নির্ধারিত ফাইল আনার সাথে একটি স্থানীয় ইনভেন্টরি ডেটা উত্স সেট আপ করুন৷
আপনি একটি স্থানীয় ইনভেন্টরি ডেটা উত্স তৈরি করতে পারেন যা একটি নির্দিষ্ট URL থেকে একটি সময়সূচীতে স্বয়ংক্রিয়ভাবে একটি ফাইল আনয়ন করে৷ আঞ্চলিক ইনভেন্টরির জন্য অনুরূপ ডেটা উত্স তৈরি করতে, অনুরোধের অংশে localInventoryDataSource
ক্ষেত্রটিকে regionalInventoryDataSource
দিয়ে প্রতিস্থাপন করুন।
ডেটা উৎস তৈরি করতে, dataSources.create
পদ্ধতি ব্যবহার করুন এবং fetchSettings
কনফিগার করা সহ একটি fileInput
অবজেক্ট প্রদান করুন।
POST https://merchantapi.googleapis.com/datasources/v1/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"
}
}
নিম্নলিখিত কোড নমুনাগুলি দেখায় যে কীভাবে নির্ধারিত আনার সাথে একটি স্থানীয় ইনভেন্টরি ডেটা উত্স তৈরি করতে হয়৷
জাভা
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.datasources.v1.CreateDataSourceRequest;
import com.google.shopping.merchant.datasources.v1.DataSource;
import com.google.shopping.merchant.datasources.v1.DataSourcesServiceClient;
import com.google.shopping.merchant.datasources.v1.DataSourcesServiceSettings;
import com.google.shopping.merchant.datasources.v1.FileInput;
import com.google.shopping.merchant.datasources.v1.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);
}
}
পিএইচপি
use Google\ApiCore\ApiException;
use Google\Shopping\Merchant\DataSources\V1\Client\DataSourcesServiceClient;
use Google\Shopping\Merchant\DataSources\V1\CreateDataSourceRequest;
use Google\Shopping\Merchant\DataSources\V1\DataSource;
use Google\Shopping\Merchant\DataSources\V1\FileInput;
use Google\Shopping\Merchant\DataSources\V1\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();
পাইথন
from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.shopping.merchant_datasources_v1 import CreateDataSourceRequest
from google.shopping.merchant_datasources_v1 import DataSource
from google.shopping.merchant_datasources_v1 import DataSourcesServiceClient
from google.shopping.merchant_datasources_v1 import FileInput
from google.shopping.merchant_datasources_v1 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/v1/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"
}
}
}'
API ব্যবহার করে একটি প্রচার ডেটা উৎস স্থাপন করুন
প্রচার ডেটা উত্সগুলি আপনাকে আপনার পণ্যগুলির জন্য প্রচারমূলক অফারগুলি জমা দিতে দেয়৷ আপনি আপনার প্রচারগুলির জন্য একটি API-ভিত্তিক ডেটা উত্স তৈরি করতে পারেন, যা আপনাকে ফাইলগুলি পরিচালনা করার প্রয়োজন ছাড়াই সরাসরি প্রচার ডেটা পাঠাতে দেয়৷
dataSources.create
পদ্ধতি ব্যবহার করুন এবং promotionDataSource
নির্দিষ্ট করুন। একটি API ফিডের জন্য, fileInput
ক্ষেত্রটি বাদ দিন।
POST https://merchantapi.googleapis.com/datasources/v1/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"
}
নিম্নলিখিত কোড নমুনাগুলি দেখায় কিভাবে একটি API-ভিত্তিক প্রচার ডেটা উৎস তৈরি করতে হয়।
জাভা
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.datasources.v1.CreateDataSourceRequest;
import com.google.shopping.merchant.datasources.v1.DataSource;
import com.google.shopping.merchant.datasources.v1.DataSourcesServiceClient;
import com.google.shopping.merchant.datasources.v1.DataSourcesServiceSettings;
import com.google.shopping.merchant.datasources.v1.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);
}
}
পিএইচপি
use Google\ApiCore\ApiException;
use Google\Shopping\Merchant\DataSources\V1\Client\DataSourcesServiceClient;
use Google\Shopping\Merchant\DataSources\V1\CreateDataSourceRequest;
use Google\Shopping\Merchant\DataSources\V1\DataSource;
use Google\Shopping\Merchant\DataSources\V1\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();
পাইথন
from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.shopping import merchant_datasources_v1
_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_v1.DataSourcesServiceClient(
credentials=credentials
)
# Creates a PromotionDataSource.
# PromotionDataSources
# can only be created for a specific `targetCountry` and `contentLanguage`
# combination.
promotion_datasource = merchant_datasources_v1.PromotionDataSource()
promotion_datasource.target_country = "CH"
promotion_datasource.content_language = "fr"
# Creates a DataSource and populates its attributes.
data_source = merchant_datasources_v1.DataSource()
data_source.display_name = "Example DataSource"
data_source.promotion_data_source = promotion_datasource
# Creates the request.
request = merchant_datasources_v1.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/v1/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/v1/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"
}
}
বণিক পর্যালোচনার জন্য একটি ডেটা উত্স তৈরি করতে, আপনি একটি খালি merchantReviewDataSource
অবজেক্টের সাথে productReviewDataSource
অবজেক্ট প্রতিস্থাপন করে অনুরূপ অনুরোধ ব্যবহার করতে পারেন।
নিম্নলিখিত কোড নমুনাগুলি ম্যানুয়াল ফাইল আপলোডের জন্য কীভাবে একটি পণ্য পর্যালোচনা ডেটা উত্স তৈরি করতে হয় তা দেখায়৷
জাভা
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.datasources.v1.CreateDataSourceRequest;
import com.google.shopping.merchant.datasources.v1.DataSource;
import com.google.shopping.merchant.datasources.v1.DataSourcesServiceClient;
import com.google.shopping.merchant.datasources.v1.DataSourcesServiceSettings;
import com.google.shopping.merchant.datasources.v1.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/v1/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.updateAutofeedSettings
পদ্ধতি ব্যবহার করে আপনার অ্যাকাউন্টের জন্য অটোফিড বৈশিষ্ট্যটি সক্ষম বা অক্ষম করতে পারেন।
এই উদাহরণটি অ্যাকাউন্টের জন্য অটোফিডের মাধ্যমে পণ্য ক্রল করতে সক্ষম করে।
PATCH https://merchantapi.googleapis.com/accounts/v1/accounts/{ACCOUNT_ID}/autofeedSettings?updateMask=enableProducts
{
"name": "accounts/{ACCOUNT_ID}/autofeedSettings",
"enableProducts": true
}
একটি সফল অনুরোধ আপডেট করা AutofeedSettings
রিসোর্স ফেরত দেয়।
{
"name": "accounts/{ACCOUNT_ID}/autofeedSettings",
"enableProducts": true,
"eligible": true
}
নিম্নলিখিত কোড নমুনাগুলি দেখায় যে কীভাবে একটি অ্যাকাউন্টের জন্য অটোফিড সেটিংস সক্ষম করতে হয়৷
জাভা
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.protobuf.FieldMask;
import com.google.shopping.merchant.accounts.v1.AutofeedSettings;
import com.google.shopping.merchant.accounts.v1.AutofeedSettingsName;
import com.google.shopping.merchant.accounts.v1.AutofeedSettingsServiceClient;
import com.google.shopping.merchant.accounts.v1.AutofeedSettingsServiceSettings;
import com.google.shopping.merchant.accounts.v1.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);
}
}
পিএইচপি
use Google\ApiCore\ApiException;
use Google\Protobuf\FieldMask;
use Google\Shopping\Merchant\Accounts\V1\AutofeedSettings;
use Google\Shopping\Merchant\Accounts\V1\Client\AutofeedSettingsServiceClient;
use Google\Shopping\Merchant\Accounts\V1\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();
পাইথন
from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.protobuf import field_mask_pb2
from google.shopping.merchant_accounts_v1 import AutofeedSettings
from google.shopping.merchant_accounts_v1 import AutofeedSettingsServiceClient
from google.shopping.merchant_accounts_v1 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/v1/accounts/{ACCOUNT_ID}/autofeedSettings?updateMask=enableProducts" \
-H "Authorization: Bearer <API_TOKEN>" \
-H "Content-Type: application/json" \
-d '{
"name": "accounts/{ACCOUNT_ID}/autofeedSettings",
"enableProducts": true
}'