منبع داده تکمیلی را به منبع داده اولیه اضافه کنید
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
نمونه کد API Merchant برای افزودن یک منبع داده تکمیلی به منبع داده اولیه.
جاوا
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package shopping.merchant.samples.productsdatasourcesworkflow.v1;
import shopping.merchant.samples.datasources.v1.UpdateDataSourceSample;
import shopping.merchant.samples.utils.Config;
/**
* This class demonstrates how to add supplemental DataSources to the primary DataSource's default
* rule.
*/
public class AddSupplementalDataSourceToPrimaryDataSourceSample {
public static void addSupplementalDataSourceToPrimaryDataSource(
Config config,
String primaryDataSourceName,
String firstSupplementalDataSourceName,
String secondSupplementalDataSourceName)
throws Exception {
// Update the primary DataSource's default rule to include both supplemental feeds.
UpdateDataSourceSample updateDatasource = new UpdateDataSourceSample();
updateDatasource.updateDataSource(
config,
primaryDataSourceName,
firstSupplementalDataSourceName,
secondSupplementalDataSourceName);
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
// The names of the primary and supplemental datasources.
String primaryDataSourceName = "accounts/{account_id}/dataSources/{datasource_id}";
String firstSupplementalDataSourceName = "accounts/{account_id}/dataSources/{datasource_id}";
String secondSupplementalDataSourceName = "accounts/{account_id}/dataSources/{datasource_id}";
addSupplementalDataSourceToPrimaryDataSource(
config,
primaryDataSourceName,
firstSupplementalDataSourceName,
secondSupplementalDataSourceName);
}
}
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-08-21 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-21 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eThis Java code sample demonstrates how to add supplemental DataSources to a primary DataSource's default rule within the Google Merchant API.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eaddSupplementalDataSourceToPrimaryDataSource\u003c/code\u003e method updates the primary DataSource by incorporating specified supplemental feeds.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eUpdateDataSourceSample\u003c/code\u003e class is used to facilitate the update process of a given primary DataSource.\u003c/p\u003e\n"],["\u003cp\u003eThe main method showcases the configuration and invocation of the \u003ccode\u003eaddSupplementalDataSourceToPrimaryDataSource\u003c/code\u003e method with placeholders for account and datasource IDs.\u003c/p\u003e\n"],["\u003cp\u003eThe code is under the Apache License 2.0.\u003c/p\u003e\n"]]],["This Java code sample demonstrates adding supplemental DataSources to a primary DataSource's default rule. It utilizes the `UpdateDataSourceSample` class to update the primary DataSource. The `addSupplementalDataSourceToPrimaryDataSource` method takes configuration, the primary DataSource name, and two supplemental DataSource names as parameters. This method then updates the primary DataSource's rule. The `main` method sets up the configuration and specifies placeholder names for the primary and supplemental DataSources before invoking the primary method.\n"],null,["# Add supplemental data source to primary data source\n\nMerchant API code sample to add a supplemental data source to a primary data\nsource. \n\n### Java\n\n // Copyright 2024 Google LLC\n //\n // Licensed under the Apache License, Version 2.0 (the \"License\");\n // you may not use this file except in compliance with the License.\n // You may obtain a copy of the License at\n //\n // https://www.apache.org/licenses/LICENSE-2.0\n //\n // Unless required by applicable law or agreed to in writing, software\n // distributed under the License is distributed on an \"AS IS\" BASIS,\n // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n // See the License for the specific language governing permissions and\n // limitations under the License.\n\n package shopping.merchant.samples.productsdatasourcesworkflow.v1;\n import shopping.merchant.samples.datasources.v1.UpdateDataSourceSample;\n import shopping.merchant.samples.utils.Config;\n\n /**\n * This class demonstrates how to add supplemental DataSources to the primary DataSource's default\n * rule.\n */\n public class AddSupplementalDataSourceToPrimaryDataSourceSample {\n\n public static void addSupplementalDataSourceToPrimaryDataSource(\n Config config,\n String primaryDataSourceName,\n String firstSupplementalDataSourceName,\n String secondSupplementalDataSourceName)\n throws Exception {\n\n // Update the primary DataSource's default rule to include both supplemental feeds.\n UpdateDataSourceSample updateDatasource = new UpdateDataSourceSample();\n updateDatasource.updateDataSource(\n config,\n primaryDataSourceName,\n firstSupplementalDataSourceName,\n secondSupplementalDataSourceName);\n }\n\n public static void main(String[] args) throws Exception {\n Config config = Config.load();\n // The names of the primary and supplemental datasources.\n String primaryDataSourceName = \"accounts/{account_id}/dataSources/{datasource_id}\";\n String firstSupplementalDataSourceName = \"accounts/{account_id}/dataSources/{datasource_id}\";\n String secondSupplementalDataSourceName = \"accounts/{account_id}/dataSources/{datasource_id}\";\n\n addSupplementalDataSourceToPrimaryDataSource(\n config,\n primaryDataSourceName,\n firstSupplementalDataSourceName,\n secondSupplementalDataSourceName);\n }\n } \n https://github.com/google/merchant-api-samples/blob/c6de994268c785ce22af0065932518a9ac5b3c03/java/src/main/java/shopping/merchant/samples/productsdatasourcesworkflow/v1/AddSupplementalDataSourceToPrimaryDataSourceSample.java"]]