Otomatik veri kaynakları, ürün verilerinizi Google'a göndermeyi kolaylaştırır. Bu veri kaynakları, web sitenizdeki ilgili ürünlerle ilgili en güncel bilgilerin Google'a ulaşmasını sağlar.
Bu sayfada, ürün eklemenize olanak tanıyan veri kaynaklarınızı programlı olarak nasıl oluşturacağınız ve güncelleyeceğiniz gösterilmektedir.
Content API for Shopping, birincil veri kaynakları oluşturmanıza olanak tanır. Satıcı Veri Kaynakları API'si ile aşağıdaki veri kaynağı türlerini de oluşturabilirsiniz:
- Birincil ürün veri kaynakları
- Ek ürün veri kaynakları
- Yerel envanter veri kaynakları
- Bölgesel envanter veri kaynakları
- Promosyon veri kaynakları
- Ürün yorumu veri kaynakları
- Satıcı yorumu veri kaynakları
Content API for Shopping, yalnızca dosya girişi olan veri kaynaklarını yönetmenize olanak tanır. Merchant API, veri kaynaklarını hem dosya hem de API girişleriyle yönetmenize olanak tanır.
Bu özelliğin Alışveriş için Content API ile karşılaştırması hakkında daha fazla bilgi edinmek için Veri kaynakları yönetimini taşıma başlıklı makaleyi inceleyin.
Merchant Center Veri Kaynakları API'yi kullanarak şunları yapabilirsiniz:
- Belirli bir
feedLabel
vecontentLanguage
içeren birincil veri kaynağı oluşturun. feedLabel
vecontentLanguage
alanlarının ayarlanmadığı bir veri kaynağı oluşturun. Bu tür bir veri kaynağı kullanarak,feedLabel
vecontentLanguage
'nin farklı kombinasyonlarını içeren ürünleri tek bir veri kaynağına ekleyebileceğiniz için ürünleriniz için birden fazla ülkeyi hedefleyebilirsiniz.- Mevcut bir birincil veri kaynağına bağlamak için ek veri kaynağı oluşturun.
- Dosya veri kaynağı için bir plan oluşturun.
- Hesabınızı veri kaynaklarının otomatik olarak yönetilmesi için kaydedin.
- API veri kaynaklarını yönetin.
- Birincil ürün veri kaynaklarını kullanarak veri kaynaklarının varsayılan kuralını yönetin.
- Promosyonlar gibi diğer veri kaynaklarını kullanın.
Veri kaynakları kanalları hakkında daha fazla bilgi için Kanallar başlıklı makaleyi inceleyin.
Ön koşullar
- Hesabınız tek yerel ayar feed'lerine taşınmış olmalıdır.
Hesabın veri hedefi bölme işlemine taşındığını doğrulamak için veri kaynağı listesini veya get yöntemlerini kullanın. Uygun değilseniz aşağıdaki istisna mesajını alırsınız ve destek ekibiyle iletişime geçmeniz gerekir.
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.
Veri kaynağı oluşturma
Birincil veri kaynakları, Merchant Center envanterinizin ana veri kaynaklarıdır. Yalnızca birincil veri kaynağı kullanarak ürün ekleyebilir veya kaldırabilirsiniz. Birincil veri kaynağınıza eklediğiniz her ürün Merchant Center'ın veri ve uygunluk şartlarını karşılıyorsa başka veri kaynağı oluşturmanız gerekmez.
Belirli bir feedLabel
ve contentLanguage
içeren birincil veri kaynağı oluşturmak için feedLabel
ve contentLanguage
alanlarını türe özgü yapılandırmada ayarlayın. Bu alanlar hakkında daha fazla bilgi için PrimaryProductDataSource
bölümüne bakın.
Aşağıdaki örnek istek, birincil ürün veri kaynağının nasıl oluşturulacağını gösterir:
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"
}
}
Aşağıdakini değiştirin:
- {ACCOUNT_ID}: Merchant Center hesabınızın benzersiz tanımlayıcısı.
- {DISPLAY_NAME}: Veri kaynağının görünen adı.
- {CONTENT_LANGUAGE}: Veri kaynağındaki ürünlerin iki harfli ISO 639-1 dil kodu.
- {FEED_LABEL}: Veri kaynağının feed etiketi.
- {COUNTRY}: Veri kaynağı kullanılarak yüklenecek ürünlerin hedef ülkesinin CLDR bölge kodu.
İstek başarıyla çalıştırıldıktan sonra aşağıdaki yanıtı görürsünüz:
{
"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"
}
Veri kaynağı oluşturma hakkında daha fazla bilgi için accounts.dataSources.create yöntemine bakın.
Yeni oluşturduğunuz veri kaynağını görüntülemek için accounts.dataSources.get veya accounts.dataSources.list yöntemini kullanın.
Aşağıdaki örnekte, GB
ve en
feedLabel
ve contentLanguage
kombinasyonu için birincil ürün veri kaynağının nasıl oluşturulacağı gösterilmektedir.
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);
}
}
Birden fazla ülkeyi hedeflemenize yardımcı olacak yeni bir birincil veri kaynağı oluşturma
Birden fazla ülkeyi hedeflemenize yardımcı olacak yeni bir birincil feed oluşturmak için PrimaryProductDataSource
kullanarak veri kaynağınızı yapılandırın ve feedLabel
ile contentLanguage
alanlarını ayarlamayın.
Content API for Shopping'i kullandığınızda sizin için yalnızca bir API veri kaynağı oluşturulur. Merchant Data Sources API'yi kullanarak birden fazla API veri kaynağı oluşturabilirsiniz. Bunlardan bazıları feedLabel
ve contentLanguage
alanları ayarlanmamış olabilir.
Yalnızca API girişi olan veri kaynaklarında feedLabel
ve contentLanguage
alanları ayarlanmamış olabilir. Bu tür veri kaynakları, dosya girişlerinde desteklenmez.
Ek veri kaynağı oluşturun ve birincil veri kaynağına bağlayın
Ek veri kaynakları yalnızca bir veya daha fazla birincil veri kaynağında zaten bulunan ürün verilerini güncellemek için kullanılır. Birden fazla ek veri kaynağınız olabilir ve her biri, istenilen sayıda birincil veri kaynağına veri sağlayabilir.
accounts.productInputs.insert
ve accounts.productInputs.delete
yöntemlerini çağırırken veri kaynağının benzersiz tanımlayıcısını sorgu parametresi olarak ekleyerek ürün verilerinde kısmi güncellemeler yapmak için ek veri kaynaklarını kullanabilirsiniz. Ek veri kaynaklarını yalnızca mevcut ürünleri güncellemek için kullanabilirsiniz.
Ek veri kaynağı oluşturmak için SupplementalProductDataSource
kullanarak veri kaynağınızı yapılandırın ve ardından birincil veri kaynağınızdaki defaultRule
alanını güncelleyerek veri kaynağınızı bağlayın.
Ek dosya veri kaynaklarında feedLabel
ve contentLanguage
alanları ayarlanmalıdır. Ek API veri kaynaklarında feedLabel
ve contentLanguage
alanlarının değeri her zaman ayarlanmamış olmalıdır.
Aşağıdaki örnekte, en
ve GB
contentLanguage
ve feedLabel
kombinasyonu için nasıl dosya ek ürün verisi kaynağı oluşturabileceğiniz gösterilmektedir.
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);
}
}
Tüm feedLabel
ve contentLanguage
kombinasyonları için çalışan ek bir veri kaynağı oluşturmak üzere aşağıdaki örneği çalıştırın.
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);
}
}
Dosya veri kaynağınız için plan oluşturma
Dosya feed'iniz için bir program oluşturmak istiyorsanız veri kaynağınızı FileInput
alanını kullanarak dosya veri kaynağı olarak yapılandırın ve ardından FileInput.FetchSettings
alanını kullanarak fetchsettings
ayarlarını yapın.
Veri kaynağını silme
Hesabınızdaki mevcut bir veri kaynağını silmek için accounts.dataSources.delete
yöntemini kullanın.
Aşağıdaki örnekte, bir veri kaynağını silmek için DeleteDataSourceRequest
paketini nasıl kullanabileceğiniz gösterilmektedir.
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);
}
}
Veri kaynağını getirme
Veri kaynağında yapılandırılmış bir dosyayı almak için accounts.dataSources.fetch
yöntemini kullanın. Bu yöntem, hesabınızdaki bir veri kaynağında veri getirme işlemini hemen gerçekleştirir. Bu yöntem yalnızca dosya girişi ayarlanmış veri kaynaklarında çalışır.
Veri kaynağı alma
Hesabınızın veri kaynağı yapılandırmasını almak için accounts.dataSources.get
yöntemini kullanın.
Aşağıdaki örnekte, belirli bir Merchant Center hesabı için belirli bir veri kaynağını almak üzere GetDataSourceRequest
paketini nasıl kullanabileceğiniz gösterilmektedir.
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);
}
}
Veri kaynağını listeleme
Hesabınızdaki veri kaynaklarının yapılandırmalarını listelemek için accounts.dataSources.list
yöntemini kullanın.
Aşağıdaki örnekte, belirli bir Merchant Center hesabının tüm veri kaynaklarını listelemek için ListDataSourceRequest
paketini nasıl kullanabileceğiniz gösterilmektedir.
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);
}
}
Veri kaynağına yama uygulama
Mevcut bir veri kaynağının yapılandırmasını güncellemek için accounts.dataSources.patch
yöntemini kullanın.
Aşağıdaki örnekte, bir veri kaynağını güncellemek için UpdateDataSourceRequest
paketini nasıl kullanabileceğiniz gösterilmektedir. Ayrıca, birincil bir veri kaynağının varsayılan kuralına ek veri kaynakları eklemek için nasıl güncelleneceği de gösterilmektedir.
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);
}
}
Veri kaynaklarını bağlama
Birincil ürün veri kaynakları, veri kaynaklarının varsayılan kuralını yönetmenize olanak tanır. Varsayılan kural, veri kaynağınızdaki tüm özellikler için geçerli olan kuraldır. Varsayılan kural, veri kaynağı oluşturulurken veya varsayılan kural alanı aracılığıyla mevcut bir veri kaynağı güncellenerek ayarlanabilir.
Kural oluşturma hakkında daha fazla bilgi için Ürün veri kaynaklarınız için kurallar oluşturma başlıklı makaleyi inceleyin.
Aşağıdaki örnek yapılandırma, tüm özelliklerin önce 1001
benzersiz tanımlayıcısıyla veri kaynağından alınmasını sağlar. Ardından, eksik özellikler birincil veri kaynağından eklenir. Diğer veri kaynaklarında sağlanmamışsa kalan özellikler, 1002
benzersiz tanımlayıcısıyla ek veri kaynağından alınır. Aynı özellik birden fazla veri kaynağında sağlanırsa listede daha üst sıradaki değer seçilir.
defaultRule {
takeFromDataSources: [
'1001', // Supplemental product data source
'self', // Self reference to the primary data source
'1002' // Supplemental product data source
]
}
Feed'lerin otomatik yönetimi
Hesabınızı veri kaynaklarının otomatik yönetimi için kaydetmek üzere aşağıdakileri yapmanız gerekir:
accounts.autofeedSettings.getAutofeedSettings
yöntemini çağırarak hesabınızın kayıt için uygun olup olmadığını kontrol edin.- Hesabınızın pazar yeri hesabı olmadığından emin olun.
Hesabınız kayıt için uygun hale geldikten sonra, veri kaynaklarının otomatik yönetimini etkinleştirmek için accounts.autofeedSettings.updateAutofeedSettings
yöntemini kullanabilirsiniz. Veri kaynaklarının otomatik yönetimini etkinleştirmek, Google'ın online mağazanızdaki ürünlerinizi otomatik olarak eklemesine ve Google platformlarında her zaman güncel olmasını sağlamaya olanak tanır.
Dosya yükleme durumunu alma
Dosya, getirme veya e-tablo içeren bir veri kaynağının durumunu almak için accounts.dataSources.fileUploads
hizmetinin GET
yöntemini çağırabilirsiniz. Veri kaynağı işleme işlemi tamamlandığında veri kaynağının son getirilmesinin sonucunu asynkron olarak hesaplamak için ad tanımlayıcısı latest
'ü kullanın.
GET https://merchantapi.googleapis.com/accounts/v1beta/{ACCOUNT_ID} /datasources/{DATASOURCE_ID} /fileUploads/latest
Dosya yükleme durumu, olası sorunlar da dahil olmak üzere ürünlerinizin ayrıntılı bir görünümünü içerebilir.
Dosya hiç yüklenmemişse dosya yükleme durumunun mevcut olmayabileceğini unutmayın. Dosya yükleme işlemi, dosya yüklendikten kısa bir süre sonra istenirse işleme durumunda olabilir.