แหล่งข้อมูลอัตโนมัติช่วยให้ส่งข้อมูลผลิตภัณฑ์ไปยัง Google ได้ง่ายขึ้น แหล่งข้อมูลเหล่านี้ช่วยให้มั่นใจได้ว่าข้อมูลล่าสุดเกี่ยวกับผลิตภัณฑ์ที่เกี่ยวข้องจากเว็บไซต์จะไปถึง Google
หน้านี้แสดงวิธีสร้างและอัปเดตแหล่งข้อมูลแบบเป็นโปรแกรมซึ่งช่วยให้คุณแทรกผลิตภัณฑ์ได้
Content API for Shopping ช่วยให้คุณสร้างแหล่งข้อมูลหลักได้ เมื่อใช้ Merchant Data Sources API คุณยังสร้างแหล่งข้อมูลประเภทต่อไปนี้ได้ด้วย
- แหล่งข้อมูลผลิตภัณฑ์หลัก
- แหล่งข้อมูลผลิตภัณฑ์เสริม
- แหล่งข้อมูลสินค้าคงคลังในร้าน
- แหล่งข้อมูลสินค้าคงคลังระดับภูมิภาค
- แหล่งข้อมูลโปรโมชัน
- แหล่งข้อมูลรีวิวผลิตภัณฑ์
- แหล่งข้อมูลรีวิวของผู้ขาย
Content API for Shopping ช่วยให้คุณจัดการแหล่งข้อมูลด้วยอินพุตไฟล์เท่านั้น Merchant API ช่วยให้คุณจัดการแหล่งข้อมูลได้โดยใช้ทั้งอินพุตไฟล์และ API
ดูข้อมูลเพิ่มเติมเกี่ยวกับความแตกต่างระหว่างเครื่องมือนี้กับ Content API for Shopping ได้ที่ย้ายข้อมูลการจัดการแหล่งข้อมูล
เมื่อใช้ Merchant Data Sources API คุณจะทำสิ่งต่อไปนี้ได้
- สร้างแหล่งข้อมูลหลักที่มี
feedLabel
และcontentLanguage
ที่เฉพาะเจาะจง - สร้างแหล่งข้อมูลที่ไม่มีการตั้งค่าช่อง
feedLabel
และcontentLanguage
การใช้แหล่งข้อมูลประเภทนี้ช่วยให้คุณกำหนดเป้าหมายผลิตภัณฑ์ไปยังหลายประเทศได้ เนื่องจากคุณสามารถแทรกผลิตภัณฑ์ที่มีfeedLabel
และcontentLanguage
ผสมผสานกันหลายรูปแบบลงในแหล่งข้อมูลเดียว - สร้างแหล่งข้อมูลเสริมเพื่อลิงก์กับแหล่งข้อมูลหลักที่มีอยู่
- ตั้งค่ากำหนดเวลาสำหรับแหล่งข้อมูลไฟล์
- ลงทะเบียนบัญชีเพื่อการจัดการแหล่งข้อมูลโดยอัตโนมัติ
- จัดการแหล่งข้อมูล API
- จัดการกฎเริ่มต้นของแหล่งข้อมูลโดยใช้แหล่งข้อมูลผลิตภัณฑ์หลัก
- ใช้แหล่งข้อมูลประเภทอื่นๆ เช่น โปรโมชัน
ดูข้อมูลเพิ่มเติมเกี่ยวกับช่องทางแหล่งข้อมูลได้ที่ช่องทาง
ข้อกำหนดเบื้องต้น
- บัญชีของคุณต้องได้รับการย้ายข้อมูลไปยังฟีดภาษาเดียว
หากต้องการตรวจสอบว่าบัญชีย้ายข้อมูลไปยังการแยกเป้าหมายข้อมูลแล้ว ให้ใช้รายการแหล่งข้อมูลหรือเมธอด get ในกรณีที่ไม่มีสิทธิ์ คุณจะได้รับข้อความยกเว้นต่อไปนี้และควรติดต่อทีมสนับสนุน
This account is in the data sources migration process and can't be used with this API yet. Contact support for more info on when this account will be able to use the data sources endpoint.
สร้างแหล่งข้อมูล
แหล่งข้อมูลหลักคือแหล่งข้อมูลหลักสำหรับสินค้าคงคลังของ Merchant Center คุณเพิ่มหรือนำผลิตภัณฑ์ออกได้โดยใช้แหล่งข้อมูลหลักเท่านั้น หากผลิตภัณฑ์ทุกรายการที่เพิ่มลงในแหล่งข้อมูลหลักมีคุณสมบัติตรงตามข้อกำหนดด้านข้อมูลและข้อกำหนดของการได้รับสิทธิ์ของ Merchant Center คุณก็ไม่จำเป็นต้องสร้างแหล่งข้อมูลอีก
หากต้องการสร้างแหล่งข้อมูลหลักที่มี feedLabel
และ contentLanguage
ที่เฉพาะเจาะจง ให้ตั้งค่าช่อง feedLabel
และ contentLanguage
ในการกําหนดค่าเฉพาะประเภท ดูข้อมูลเพิ่มเติมเกี่ยวกับช่องเหล่านี้ได้ที่ PrimaryProductDataSource
ตัวอย่างคำขอต่อไปนี้แสดงวิธีสร้างแหล่งข้อมูลผลิตภัณฑ์หลัก
POST https://merchantapi.googleapis.com/datasources/v1beta/accounts/{ACCOUNT_ID}/dataSources
{
"displayName": "{DISPLAY_NAME}",
"primaryProductDataSource": {
"contentLanguage": "{CONTENT_LANGUAGE}",
"feedLabel": "{FEED_LABEL}",
"countries": [
"{COUNTRY}"
],
"channel": "ONLINE_PRODUCTS"
}
}
แทนที่ค่าต่อไปนี้
- {ACCOUNT_ID}: ตัวระบุที่ไม่ซ้ำของบัญชี Merchant Center
- {DISPLAY_NAME}: ชื่อที่แสดงของแหล่งข้อมูล
- {CONTENT_LANGUAGE}: รหัสภาษา 2 ตัวอักษรตามมาตรฐาน ISO 639-1 ของผลิตภัณฑ์ในแหล่งข้อมูล
- {FEED_LABEL}: ป้ายกํากับฟีดของแหล่งข้อมูล
- {COUNTRY}: รหัสเขตแดน CLDR ของประเทศเป้าหมายของผลิตภัณฑ์ที่จะอัปโหลดโดยใช้แหล่งข้อมูล
หลังจากคําขอทํางานสําเร็จแล้ว คุณจะเห็นการตอบกลับต่อไปนี้
{
"name": "accounts/{ACCOUNT_ID}/dataSources/{DATASOURCE_ID}",
"dataSourceId": "{DATASOURCE_ID}",
"displayName": "{DISPLAY_NAME}",
"primaryProductDataSource": {
"channel": "ONLINE_PRODUCTS",
"feedLabel": "{FEED_LABEL}",
"contentLanguage": "{CONTENT_LANGUAGE}",
"countries": [
"{COUNTRY}"
],
"defaultRule": {
"takeFromDataSources": [
{
"self": true
}
]
}
},
"input": "API"
}
ดูข้อมูลเพิ่มเติมเกี่ยวกับการสร้างแหล่งข้อมูลได้ที่เมธอด accounts.dataSources.create
หากต้องการดูแหล่งข้อมูลที่สร้างขึ้นใหม่ ให้ใช้เมธอด accounts.dataSources.get หรือ accounts.dataSources.list
ตัวอย่างต่อไปนี้แสดงวิธีสร้างแหล่งข้อมูลผลิตภัณฑ์หลักสำหรับชุดค่าผสม GB
และ en
feedLabel
และ contentLanguage
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.PrimaryProductDataSource;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/**
* This class demonstrates how to create a primary product datasource for all `feedLabel` and
* `contentLanguage` combinations. Note that rules functionality is limited for wildcard feeds.
*/
public class CreatePrimaryProductDataSourceWildCardSample {
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());
// The type of data that this datasource will receive.
PrimaryProductDataSource primaryProductDataSource =
PrimaryProductDataSource.newBuilder()
// Channel can be "ONLINE_PRODUCTS" or "LOCAL_PRODUCTS" or "PRODUCTS" .
// While accepted, datasources with channel "products" representing unified products
// currently cannot be used with the Products bundle.
.setChannel(PrimaryProductDataSource.Channel.ONLINE_PRODUCTS)
.addCountries("GB")
.build();
try (DataSourcesServiceClient dataSourcesServiceClient =
DataSourcesServiceClient.create(dataSourcesServiceSettings)) {
CreateDataSourceRequest request =
CreateDataSourceRequest.newBuilder()
.setParent(parent)
.setDataSource(
DataSource.newBuilder()
.setDisplayName(displayName)
.setPrimaryProductDataSource(primaryProductDataSource)
.build())
.build();
System.out.println("Sending Create PrimaryProduct DataSource request");
DataSource response = dataSourcesServiceClient.createDataSource(request);
System.out.println("Created DataSource Name below");
System.out.println(response.getName());
return response.getName();
} catch (Exception e) {
System.out.println(e);
System.exit(1);
// Null is necessary to satisfy the compiler as we're not returning a String on failure.
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 = "Primary Product Data Wildcard";
createDataSource(config, displayName);
}
}
สร้างแหล่งข้อมูลหลักใหม่ซึ่งช่วยกําหนดเป้าหมายหลายประเทศ
หากต้องการสร้างฟีดหลักใหม่ที่ช่วยให้คุณกำหนดเป้าหมายหลายประเทศ ให้กำหนดค่าแหล่งข้อมูลโดยใช้ PrimaryProductDataSource
และอย่าตั้งค่าฟิลด์ feedLabel
และ contentLanguage
เมื่อใช้ Content API for Shopping ระบบจะสร้างแหล่งข้อมูล API ให้คุณเพียงแหล่งเดียว เมื่อใช้ Merchant Data Sources API คุณจะมีแหล่งข้อมูล API ได้หลายแหล่ง โดยแหล่งข้อมูลบางแหล่งอาจไม่มีการตั้งค่าช่อง feedLabel
และ contentLanguage
เฉพาะแหล่งข้อมูลที่มีอินพุต API เท่านั้นที่จะตั้งค่าฟิลด์ feedLabel
และ contentLanguage
ไม่ได้ แหล่งข้อมูลประเภทนี้ไม่รองรับการป้อนข้อมูลไฟล์
สร้างแหล่งข้อมูลเสริมและลิงก์กับแหล่งข้อมูลหลัก
แหล่งข้อมูลเสริมจะใช้สำหรับอัปเดตข้อมูลผลิตภัณฑ์ที่มีอยู่แล้วในแหล่งข้อมูลหลักอย่างน้อย 1 รายการเท่านั้น คุณมีแหล่งข้อมูลเสริมได้หลายแหล่ง โดยแหล่งข้อมูลเสริมแต่ละแหล่งจะเสริมข้อมูลในแหล่งข้อมูลหลักกี่แหล่งก็ได้
คุณสามารถใช้แหล่งข้อมูลเสริมเพื่ออัปเดตข้อมูลผลิตภัณฑ์บางส่วนได้โดยเพิ่มตัวระบุที่ไม่ซ้ำกันของแหล่งข้อมูลเป็นพารามิเตอร์การค้นหาเมื่อเรียกใช้เมธอด accounts.productInputs.insert
และ accounts.productInputs.delete
คุณใช้แหล่งข้อมูลเสริมเพื่ออัปเดตผลิตภัณฑ์ที่มีอยู่ได้เท่านั้น
หากต้องการสร้างแหล่งข้อมูลเสริม ให้กําหนดค่าแหล่งข้อมูลโดยใช้ SupplementalProductDataSource
จากนั้นลิงก์โดยอัปเดตฟิลด์ defaultRule
ในแหล่งข้อมูลหลัก
แหล่งข้อมูลไฟล์เสริมต้องมีการตั้งค่าช่อง feedLabel
และ contentLanguage
แหล่งข้อมูล API เสริมต้องไม่มีการตั้งค่าฟิลด์ feedLabel
และ
contentLanguage
เสมอ
ตัวอย่างต่อไปนี้แสดงวิธีสร้างแหล่งข้อมูลผลิตภัณฑ์เสริมของไฟล์สำหรับชุดค่าผสม en
และ GB
contentLanguage
และ feedLabel
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.SupplementalProductDataSource;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/**
* This class demonstrates how to create a File Supplemental product datasource for the "en" and
* "GB" `feedLabel` and `contentLanguage` combination. This supplemental feed is eligible to be
* linked to both a wildcard primary feed and/or a primary feed with the same `feedLabel` and
* `contentLanguage` combination.
*/
public class CreateFileSupplementalProductDataSourceSample {
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 Supplemental 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());
try (DataSourcesServiceClient dataSourcesServiceClient =
DataSourcesServiceClient.create(dataSourcesServiceSettings)) {
CreateDataSourceRequest request =
CreateDataSourceRequest.newBuilder()
.setParent(parent)
.setDataSource(
DataSource.newBuilder()
.setDisplayName(displayName)
.setSupplementalProductDataSource(
SupplementalProductDataSource.newBuilder()
.setContentLanguage("en")
.setFeedLabel("GB")
.build())
.setFileInput(fileInput)
.build())
.build();
System.out.println("Sending create SupplementalProduct DataSource request");
DataSource response = dataSourcesServiceClient.createDataSource(request);
System.out.println("Created DataSource Name below");
System.out.println(response.getName());
return response.getName();
} catch (Exception e) {
System.out.println(e);
System.exit(1);
// Null is necessary to satisfy the compiler as we're not returning a String on failure.
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 File Supplemental Product Data";
// The file input data that this datasource will receive.
FileInput fileInput = setFileInput();
createDataSource(config, displayName, fileInput);
}
}
หากต้องการสร้างแหล่งข้อมูลเสริมที่ใช้งานได้กับชุดค่าผสม feedLabel
และ contentLanguage
ทั้งหมด ให้เรียกใช้ตัวอย่างต่อไปนี้
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.SupplementalProductDataSource;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/**
* This class demonstrates how to create a Supplemental product datasource all `feedLabel` and
* `contentLanguage` combinations. This works only for API supplemental feeds.
*/
public class CreateSupplementalProductDataSourceWildCardSample {
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)
.setSupplementalProductDataSource(
SupplementalProductDataSource.newBuilder().build())
.build())
.build();
System.out.println("Sending create SupplementalProduct DataSource request");
DataSource response = dataSourcesServiceClient.createDataSource(request);
System.out.println("Created DataSource Name below");
System.out.println(response.getName());
return response.getName();
} catch (Exception e) {
System.out.println(e);
System.exit(1);
return null; // Necessary to satisfy the compiler as we're not returning a
// String on failure.
}
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
// The displayed datasource name in the Merchant Center UI.
String displayName = "Supplemental API Product Data Wildcard";
createDataSource(config, displayName);
}
}
ตั้งกําหนดเวลาสําหรับแหล่งข้อมูลไฟล์
หากต้องการตั้งเวลาฟีดไฟล์ ให้กําหนดค่าแหล่งข้อมูลเป็นแหล่งข้อมูลไฟล์โดยใช้ช่อง FileInput
จากนั้นตั้งค่า fetchsettings
โดยใช้ช่อง FileInput.FetchSettings
ลบแหล่งข้อมูล
หากต้องการลบแหล่งข้อมูลที่มีอยู่ออกจากบัญชี ให้ใช้วิธีนี้
accounts.dataSources.delete
ตัวอย่างต่อไปนี้แสดงวิธีใช้แพ็กเกจ DeleteDataSourceRequest
เพื่อลบแหล่งข้อมูล
Java
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.datasources.v1beta.DataSourceName;
import com.google.shopping.merchant.datasources.v1beta.DataSourcesServiceClient;
import com.google.shopping.merchant.datasources.v1beta.DataSourcesServiceSettings;
import com.google.shopping.merchant.datasources.v1beta.DeleteDataSourceRequest;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/** This class demonstrates how to delete a datasource. */
public class DeleteDataSourceSample {
public static void deleteDataSource(Config config, String dataSourceId) throws Exception {
GoogleCredentials credential = new Authenticator().authenticate();
DataSourcesServiceSettings dataSourcesServiceSettings =
DataSourcesServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
String name =
DataSourceName.newBuilder()
.setAccount(config.getAccountId().toString())
.setDatasource(dataSourceId)
.build()
.toString();
try (DataSourcesServiceClient dataSourcesServiceClient =
DataSourcesServiceClient.create(dataSourcesServiceSettings)) {
DeleteDataSourceRequest request = DeleteDataSourceRequest.newBuilder().setName(name).build();
System.out.println("Sending deleteDataSource request");
// Delete works for any datasource type.
// If Type "Supplemental", delete will only work if it's not linked to any primary feed.
// If a link exists and the Type is "Supplemental", you will need to remove the supplemental
// feed from the default and/or custom rule(s) of any primary feed(s) that references it. Then
// retry the delete.
dataSourcesServiceClient.deleteDataSource(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.");
} catch (Exception e) {
System.out.println(e);
}
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
// An ID automatically assigned to the datasource after creation by Google.
String dataSourceId = "1111111111"; // Replace with your datasource ID.
deleteDataSource(config, dataSourceId);
}
}
ดึงข้อมูลแหล่งข้อมูล
หากต้องการดึงข้อมูลไฟล์ที่กําหนดค่าไว้ในแหล่งข้อมูล ให้ใช้วิธี accounts.dataSources.fetch
วิธีนี้จะดึงข้อมูลในแหล่งข้อมูลจากบัญชีของคุณโดยทันที วิธีการนี้ใช้ได้กับแหล่งข้อมูลที่มีการตั้งค่าการป้อนข้อมูลไฟล์เท่านั้น
รับแหล่งข้อมูล
หากต้องการเรียกข้อมูลการกําหนดค่าแหล่งข้อมูลสําหรับบัญชี ให้ใช้เมธอด accounts.dataSources.get
ตัวอย่างต่อไปนี้แสดงวิธีใช้แพ็กเกจ GetDataSourceRequest
เพื่อดึงข้อมูลแหล่งที่มาที่เฉพาะเจาะจงสำหรับบัญชี Merchant Center หนึ่งๆ
Java
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.datasources.v1beta.DataSource;
import com.google.shopping.merchant.datasources.v1beta.DataSourceName;
import com.google.shopping.merchant.datasources.v1beta.DataSourcesServiceClient;
import com.google.shopping.merchant.datasources.v1beta.DataSourcesServiceSettings;
import com.google.shopping.merchant.datasources.v1beta.GetDataSourceRequest;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/** This class demonstrates how to get a specific datasource for a given Merchant Center account. */
public class GetDataSourceSample {
public static DataSource getDataSource(Config config, String dataSourceId) throws Exception {
// Obtains OAuth token based on the user's configuration.
GoogleCredentials credential = new Authenticator().authenticate();
// Creates service settings using the credentials retrieved above.
DataSourcesServiceSettings dataSourcesServiceSettings =
DataSourcesServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
// Creates datasource name to identify datasource.
String name =
DataSourceName.newBuilder()
.setAccount(config.getAccountId().toString())
.setDatasource(dataSourceId)
.build()
.toString();
// Calls the API and catches and prints any network failures/errors.
try (DataSourcesServiceClient dataSourcesServiceClient =
DataSourcesServiceClient.create(dataSourcesServiceSettings)) {
// The name has the format: accounts/{account}/datasources/{datasource}
GetDataSourceRequest request = GetDataSourceRequest.newBuilder().setName(name).build();
System.out.println("Sending GET DataSource request:");
DataSource response = dataSourcesServiceClient.getDataSource(request);
System.out.println("Retrieved DataSource below");
System.out.println(response);
return response;
} catch (Exception e) {
System.out.println(e);
System.exit(1);
return null; // Necessary to satisfy the compiler as we're not returning a
// DataSource on failure.
}
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
// An ID assigned to a datasource by Google.
String datasourceId = "1111111111"; // Replace with your datasource ID.
getDataSource(config, datasourceId);
}
}
แสดงรายการแหล่งข้อมูล
หากต้องการแสดงรายการการกําหนดค่าแหล่งข้อมูลสําหรับบัญชี ให้ใช้วิธี accounts.dataSources.list
ตัวอย่างต่อไปนี้แสดงวิธีใช้แพ็กเกจ ListDataSourceRequest
เพื่อแสดงแหล่งข้อมูลทั้งหมดของบัญชี Merchant Center หนึ่งๆ
Java
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.datasources.v1beta.DataSource;
import com.google.shopping.merchant.datasources.v1beta.DataSourcesServiceClient;
import com.google.shopping.merchant.datasources.v1beta.DataSourcesServiceClient.ListDataSourcesPagedResponse;
import com.google.shopping.merchant.datasources.v1beta.DataSourcesServiceSettings;
import com.google.shopping.merchant.datasources.v1beta.ListDataSourcesRequest;
import java.util.ArrayList;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/** This class demonstrates how to list all the datasources for a given Merchant Center account */
public class ListDataSourcesSample {
private static String getParent(String accountId) {
return String.format("accounts/%s", accountId);
}
public static ArrayList<DataSource> listDataSources(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.
DataSourcesServiceSettings dataSourcesServiceSettings =
DataSourcesServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
// Creates parent to identify the account from which to list all the datasources.
String parent = getParent(config.getAccountId().toString());
// Calls the API and catches and prints any network failures/errors.
try (DataSourcesServiceClient dataSourcesServiceClient =
DataSourcesServiceClient.create(dataSourcesServiceSettings)) {
// The parent has the format: accounts/{account}
ListDataSourcesRequest request =
ListDataSourcesRequest.newBuilder().setParent(parent).build();
System.out.println("Sending list datasources request:");
ListDataSourcesPagedResponse response = dataSourcesServiceClient.listDataSources(request);
int count = 0;
ArrayList<DataSource> dataSources = new ArrayList<DataSource>();
ArrayList<DataSource> justPrimaryDataSources = new ArrayList<DataSource>();
// 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 (DataSource element : response.iterateAll()) {
System.out.println(element);
count++;
dataSources.add(element);
// The below lines show how to filter datasources based on type.
// `element.hasSupplementalProductDataSource()` would give you supplemental
// datasources, etc.
if (element.hasPrimaryProductDataSource()) {
justPrimaryDataSources.add(element);
}
}
System.out.print("The following count of elements were returned: ");
System.out.println(count);
return dataSources;
} catch (Exception e) {
System.out.println(e);
System.exit(1);
return null; // Necessary to satisfy the compiler as we're not returning an
// ArrayList<DataSource> on failure.
}
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
listDataSources(config);
}
}
แหล่งข้อมูลการแพตช์
หากต้องการอัปเดตการกําหนดค่าของแหล่งข้อมูลที่มีอยู่ ให้ใช้เมธอด accounts.dataSources.patch
ตัวอย่างต่อไปนี้แสดงวิธีใช้แพ็กเกจ UpdateDataSourceRequest
เพื่ออัปเดตแหล่งข้อมูล รวมถึงแสดงวิธีอัปเดตแหล่งข้อมูลหลักเพื่อเพิ่มแหล่งข้อมูลเสริมลงในกฎเริ่มต้น
Java
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.protobuf.FieldMask;
import com.google.shopping.merchant.datasources.v1beta.DataSource;
import com.google.shopping.merchant.datasources.v1beta.DataSourceName;
import com.google.shopping.merchant.datasources.v1beta.DataSourceReference;
import com.google.shopping.merchant.datasources.v1beta.DataSourcesServiceClient;
import com.google.shopping.merchant.datasources.v1beta.DataSourcesServiceSettings;
import com.google.shopping.merchant.datasources.v1beta.PrimaryProductDataSource;
import com.google.shopping.merchant.datasources.v1beta.PrimaryProductDataSource.DefaultRule;
import com.google.shopping.merchant.datasources.v1beta.UpdateDataSourceRequest;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/**
* This class demonstrates how to update a datasource to change its name in the MC UI. It also
* demonstrates how to update a primary datasource to add supplemental datasources to its default
* rule (https://support.google.com/merchants/answer/7450276).
*/
public class UpdateDataSourceSample {
public static String updateDataSource(Config config, String displayName, String dataSourceId)
throws Exception {
GoogleCredentials credential = new Authenticator().authenticate();
DataSourcesServiceSettings dataSourcesServiceSettings =
DataSourcesServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
// Creates datasource name to identify datasource.
String name =
DataSourceName.newBuilder()
.setAccount(config.getAccountId().toString())
.setDatasource(dataSourceId)
.build()
.toString();
DataSource dataSource =
DataSource.newBuilder()
// Update the datasource to have the new display name
.setDisplayName(displayName)
.setName(name)
.build();
FieldMask fieldMask = FieldMask.newBuilder().addPaths("display_name").build();
try (DataSourcesServiceClient dataSourcesServiceClient =
DataSourcesServiceClient.create(dataSourcesServiceSettings)) {
UpdateDataSourceRequest request =
UpdateDataSourceRequest.newBuilder()
.setDataSource(dataSource)
.setUpdateMask(fieldMask)
.build();
System.out.println("Sending Update DataSource request");
DataSource response = dataSourcesServiceClient.updateDataSource(request);
System.out.println("Updated DataSource Name below");
System.out.println(response.getName());
return response.getName();
} catch (Exception e) {
System.out.println(e);
System.exit(1);
return null;
}
}
public String updateDataSource(
Config config,
String primaryDataSourceName,
String firstSupplementalDataSourceName,
String secondSupplementalDataSourceName)
throws Exception {
GoogleCredentials credential = new Authenticator().authenticate();
DataSourcesServiceSettings dataSourcesServiceSettings =
DataSourcesServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
// Setting self to 'true' refers to the primary datasource itself.
DataSourceReference dataSourceReferenceSelf =
DataSourceReference.newBuilder().setSelf(true).build();
DataSourceReference firstSupplementalDataSourceReference =
DataSourceReference.newBuilder()
.setSupplementalDataSourceName(firstSupplementalDataSourceName)
.build();
DataSourceReference secondSupplementalDataSourceReference =
DataSourceReference.newBuilder()
.setSupplementalDataSourceName(secondSupplementalDataSourceName)
.build();
// The attributes will first be taken from the primary DataSource.
// Then the first supplemental DataSource if the attribute is not in the primary DataSource
// And finally the second supplemental DataSource if not in the first two DataSources.
// Note that CustomRules could change the behavior of how updates are applied.
DefaultRule defaultRule =
DefaultRule.newBuilder()
.addTakeFromDataSources(dataSourceReferenceSelf)
.addTakeFromDataSources(firstSupplementalDataSourceReference)
.addTakeFromDataSources(secondSupplementalDataSourceReference)
.build();
// The type of data that this datasource will receive.
PrimaryProductDataSource primaryProductDataSource =
PrimaryProductDataSource.newBuilder().setDefaultRule(defaultRule).build();
DataSource dataSource =
DataSource.newBuilder()
// Update the primary datasource to have the default rule datasources in the correct
// order.
.setPrimaryProductDataSource(primaryProductDataSource)
.setName(primaryDataSourceName)
.build();
// The '.' signifies a nested field.
FieldMask fieldMask =
FieldMask.newBuilder().addPaths("primary_product_data_source.default_rule").build();
try (DataSourcesServiceClient dataSourcesServiceClient =
DataSourcesServiceClient.create(dataSourcesServiceSettings)) {
UpdateDataSourceRequest request =
UpdateDataSourceRequest.newBuilder()
.setDataSource(dataSource)
.setUpdateMask(fieldMask)
.build();
System.out.println("Sending Update DataSource request");
DataSource response = dataSourcesServiceClient.updateDataSource(request);
System.out.println("Updated 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 updated displayed datasource name in the Merchant Center UI.
String displayName = "Great Britain Primary Product Data";
// The ID of the datasource to update
String dataSourceId = "11111111"; // Replace with your datasource ID.
updateDataSource(config, displayName, dataSourceId);
}
}
ลิงก์แหล่งข้อมูล
แหล่งข้อมูลผลิตภัณฑ์หลักช่วยให้คุณจัดการกฎเริ่มต้นของแหล่งข้อมูลได้ กฎเริ่มต้นคือกฎที่ใช้กับแอตทริบิวต์ทั้งหมดในแหล่งข้อมูล คุณตั้งค่ากฎเริ่มต้นได้ขณะสร้างแหล่งข้อมูลหรืออัปเดตแหล่งข้อมูลที่มีอยู่ผ่านช่องกฎเริ่มต้น
ดูข้อมูลเพิ่มเติมเกี่ยวกับการตั้งค่ากฎได้ที่ตั้งค่ากฎสำหรับแหล่งข้อมูลผลิตภัณฑ์
การกำหนดค่าตัวอย่างต่อไปนี้ช่วยให้มั่นใจได้ว่าระบบจะนำแอตทริบิวต์ทั้งหมดจากแหล่งข้อมูลที่มีตัวระบุที่ไม่ซ้ำกัน 1001
ก่อน จากนั้นระบบจะเพิ่มแอตทริบิวต์ที่ขาดหายไปจากแหล่งข้อมูลหลัก สุดท้าย ระบบจะนำแอตทริบิวต์ที่เหลือมาจากแหล่งข้อมูลเสริมที่มีตัวระบุที่ไม่ซ้ำกัน 1002
หากไม่ได้ระบุไว้ในแหล่งข้อมูลอื่น หากระบุแอตทริบิวต์เดียวกันในแหล่งข้อมูลหลายแห่ง ระบบจะเลือกค่าที่สูงกว่าในรายการ
defaultRule {
takeFromDataSources: [
'1001', // Supplemental product data source
'self', // Self reference to the primary data source
'1002' // Supplemental product data source
]
}
การจัดการฟีดอัตโนมัติ
หากต้องการลงทะเบียนบัญชีเพื่อการจัดการแหล่งข้อมูลอัตโนมัติ คุณต้องทําดังนี้
- ตรวจสอบว่าบัญชีมีสิทธิ์ลงทะเบียนหรือไม่โดยเรียกใช้เมธอด
accounts.autofeedSettings.getAutofeedSettings
- ตรวจสอบว่าบัญชีของคุณไม่ใช่บัญชีตลาด
หลังจากบัญชีมีสิทธิ์ลงทะเบียนแล้ว คุณจะใช้วิธี accounts.autofeedSettings.updateAutofeedSettings
เพื่อเปิดใช้การจัดการแหล่งข้อมูลอัตโนมัติได้ การเปิดใช้การจัดการแหล่งข้อมูลอัตโนมัติช่วยให้ Google เพิ่มผลิตภัณฑ์จากร้านค้าออนไลน์โดยอัตโนมัติและทำให้ผลิตภัณฑ์เป็นข้อมูลล่าสุดอยู่เสมอบนแพลตฟอร์มของ Google
เรียกดูสถานะการอัปโหลดไฟล์
หากต้องการดูสถานะของแหล่งข้อมูลด้วยไฟล์ ดึงข้อมูล หรือสเปรดชีต คุณสามารถเรียกใช้เมธอด GET
ของบริการ accounts.dataSources.fileUploads
หากต้องการดูผลลัพธ์ของการดึงข้อมูลแหล่งข้อมูลที่คำนวณแบบไม่พร้อมกันครั้งล่าสุดเมื่อการประมวลผลแหล่งข้อมูลเสร็จสิ้น ให้ใช้ตัวระบุชื่อ latest
GET https://merchantapi.googleapis.com/accounts/v1beta/{ACCOUNT_ID}/datasources/{DATASOURCE_ID}/fileUploads/latest
สถานะการอัปโหลดไฟล์อาจมีมุมมองโดยละเอียดของผลิตภัณฑ์ รวมถึงปัญหาที่อาจเกิดขึ้น
โปรดทราบว่าสถานะการอัปโหลดไฟล์อาจไม่ปรากฏขึ้นหากไม่เคยอัปโหลดไฟล์ สถานะการอัปโหลดไฟล์อาจอยู่ในสถานะ "กำลังดำเนินการ" หากมีการขอหลังจากอัปโหลดไฟล์ไม่นาน