このガイドは、 スタートガイドの 許可するリクエストを作成できます。
すべての設定が完了したら、Google Content API for Shopping にリクエストを送信できます。次のコードでは、 サンプルは、いくつかの単純なリクエストを送信する方法を示しています。
- 商品を作成します。
- 商品のリストを取得します。
- リストから特定の商品を取得します。
- 商品の価格を更新します。
メソッドの完全なリストについては、 リファレンス ドキュメントをご覧ください。
詳しくは、ベスト プラクティスのページをご覧ください。 では、API の最適な使用方法を説明しています。 このページでは、バッチ リクエストが推奨される理由についても説明します。
Content API に問題がある場合は、 Merchant Center のステータス ダッシュボード(サービス停止)と、 サポートページ。
商品を作成
商品に設定可能なすべての属性について詳しくは、 商品フィード仕様をご覧ください。 商品を作成するには、 で、次のコードを使用します。
POST /content/v2.1/YOUR_MERCHANT_ID /products
{
"offerId": "book123",
"title": "A Tale of Two Cities",
"description": "A classic novel about the French Revolution",
"link": "http://my-book-shop.com/tale-of-two-cities.html",
"imageLink": "http://my-book-shop.com/tale-of-two-cities.jpg",
"contentLanguage": "en",
"targetCountry": "GB",
"feedLabel": "GB",
"channel": "online",
"availability": "in stock",
"condition": "new",
"googleProductCategory": "Media > Books",
"gtin": "9780007350896",
"price": {
"value": "2.50",
"currency": "GBP"
},
"shipping": [{
"country": "GB",
"service": "Standard shipping",
"price": {
"value": "0.99",
"currency": "GBP"
}
}],
"shippingWeight": {
"value": "200",
"unit": "grams"
}
}
Product product = new Product();
product.setOfferId("book123");
product.setTitle("A Tale of Two Cities");
product.setDescription("A classic novel about the French Revolution");
product.setLink("http://my-book-shop.com/tale-of-two-cities.html");
product.setImageLink("http://my-book-shop.com/tale-of-two-cities.jpg");
product.setContentLanguage("en");
product.setTargetCountry("GB");
product.setChannel("online");
product.setAvailability("in stock");
product.setCondition("new");
product.setGoogleProductCategory("Media > Books");
product.setGtin("9780007350896");
Price price = new Price();
price.setValue("2.50");
price.setCurrency("GBP");
product.setPrice(price);
Price shippingPrice = new Price();
shippingPrice.setValue("0.99");
shippingPrice.setCurrency("GBP");
ProductShipping shipping = new ProductShipping();
shipping.setPrice(shippingPrice);
shipping.setCountry("GB");
shipping.setService("Standard shipping");
ArrayList
$product = new Google_Service_ShoppingContent_Product();
$product->setOfferId('book123');
$product->setTitle('A Tale of Two Cities');
$product->setDescription('A classic novel about the French Revolution');
$product->setLink('http://my-book-shop.com/tale-of-two-cities.html');
$product->setImageLink('http://my-book-shop.com/tale-of-two-cities.jpg');
$product->setContentLanguage('en');
$product->setTargetCountry('GB');
$product->setChannel('online');
$product->setAvailability('in stock');
$product->setCondition('new');
$product->setGoogleProductCategory('Media > Books');
$product->setGtin('9780007350896');
$price = new Google_Service_ShoppingContent_Price();
$price->setValue('2.50');
$price->setCurrency('GBP');
$shipping_price = new Google_Service_ShoppingContent_Price();
$shipping_price->setValue('0.99');
$shipping_price->setCurrency('GBP');
$shipping = new Google_Service_ShoppingContent_ProductShipping();
$shipping->setPrice($shipping_price);
$shipping->setCountry('GB');
$shipping->setService('Standard shipping');
$shipping_weight = new Google_Service_ShoppingContent_ProductShippingWeight();
$shipping_weight->setValue(200);
$shipping_weight->setUnit('grams');
$product->setPrice($price);
$product->setShipping(array($shipping));
$product->setShippingWeight($shipping_weight);
$result = $service->products->insert($merchant_id, $product);
商品のリストを取得する
特定の プロダクトとして機能させるには、次のコードを使用します。
プロトコル
GET /content/v2.1/YOUR_MERCHANT_ID /products
Java
List productsList = service.products().list(merchantId);
ProductsListResponse page = productsList.execute();
while ((page.getResources() != null) && !page.getResources().isEmpty()) {
for (Product product : page.getResources()) {
System.out.printf("%s %s%n", product.getId(), product.getTitle());
}
if (page.getNextPageToken() == null) {
break;
}
productsList.setPageToken(page.getNextPageToken());
page = productsList.execute();
}
PHP
$products = $service->products->listProducts($merchantId);
$parameters = array();
while (!empty($products->getResources()) {
foreach ($products->getResources() as $product) {
printf("%s %s\n", $product->getId(), $product->getTitle());
}
if (!empty($products->getNextPageToken()) {
break;
}
$parameters['pageToken'] = $products->nextPageToken;
$products = $service->products->listProducts($merchantId, $parameters);
}
特定の商品を取得する
特定のデータセットを リストから商品を選択する場合は、次のコードを使用します。
プロトコル
GET /content/v2.1/YOUR_MERCHANT_ID /products/online:en:GB:book123
Java
Product product = service.products()
.get(merchantId, "online:en:GB:book123")
.execute();
System.out.printf("%s %s\n", product.getId(), product.getTitle());
PHP
$product = $service->products->get($merchant_id, 'online:en:GB:book123');
printf("%s %s\n", $product->getId(), $product->getTitle());
オンラインの商品の在庫状況を更新する
<ph type="x-smartling-placeholder"></ph>を使用できます 商品リソースの補助フィードを使用して、オンライン商品データを次のように更新します。 コード:
プロトコル
POST /content/v2.1/YOUR_MERCHANT_ID /products?YOUR_SUPPLEMENTAL_FEED_ID
{
"offerId": "book123",
"contentLanguage": "en",
"targetCountry": "GB",
"feedLabel": "GB",
"channel": "online",
"availability": "out of stock"
}
Java
Product product = new Product();
// Mandatory Fields
product.setOfferId("book123");
product.setContentLanguage("en");
product.setTargetCountry("GB");
product.setChannel("online");
// Optional Fields to Update
product.setAvailability("out of stock");
// Your unique supplemental feedId
feedId=123456789
Product result = service.products().insert(merchantId, product, feedId).execute();
PHP
$product = new Google_Service_ShoppingContent_Product();
// Mandatory Fields
$product->setOfferId('book123');
$product->setContentLanguage('en');
$product->setTargetCountry('GB');
$product->setChannel('online');
// Optional Fields to Update
$product->setAvailability('out of stock');
// Your unique supplemental feedId
$feedId=123456789
$result = $service->products->insert($merchant_id, $product, $feedId);
ローカル商品の在庫状況を更新する
ローカル在庫サービスを使用して、ローカル商品データを次のコードで更新します。
プロトコル
POST /content/v2.1/YOUR_MERCHANT_ID /localinventory/online/products/online:en:GB:book123
{
"availability": "out of stock"
}
Java
Product product = new Product();
// Mandatory Fields
product.setOfferId("book123");
product.setContentLanguage("en");
product.setTargetCountry("GB");
product.setChannel("online");
// Optional Fields to Update
product.setAvailability("out of stock");
Product result = service.localinventory().insert(merchantId, product).execute();
PHP
$product = new Google_Service_ShoppingContent_Product();
// Mandatory Fields
$product->setOfferId('book123');
$product->setContentLanguage('en');
$product->setTargetCountry('GB');
$product->setChannel('online');
// Optional Fields to Update
$product->setAvailability('out of stock');
$result = $service->localinventory->insert($merchant_id, $product);