google 内容 api 用于购物
google content api for shopping
我正在尝试使用 google 内容 api 来使用 php 进行购物。 google 文档为此提供了以下代码。但最后一行 $service 被使用但未定义。
$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);
创建服务实例。
// include your composer dependencies
require_once 'vendor/autoload.php';
putenv('GOOGLE_APPLICATION_CREDENTIALS=Merchant-Center-XXXXXx.json');
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope('https://www.googleapis.com/auth/content');
$service = new Google_Service_ShoppingContent($client);
我正在尝试使用 google 内容 api 来使用 php 进行购物。 google 文档为此提供了以下代码。但最后一行 $service 被使用但未定义。
$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);
创建服务实例。
// include your composer dependencies
require_once 'vendor/autoload.php';
putenv('GOOGLE_APPLICATION_CREDENTIALS=Merchant-Center-XXXXXx.json');
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope('https://www.googleapis.com/auth/content');
$service = new Google_Service_ShoppingContent($client);