向主要数据源添加补充数据源
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
用于向主要数据源添加补充数据源的 Merchant API 代码示例。
Java
// 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);
}
}
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-21。
[null,null,["最后更新时间 (UTC):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"]]