gpt4 book ai didi

php - 用于购物的谷歌内容 API

转载 作者:行者123 更新时间:2023-12-05 05:08:53 29 4
gpt4 key购买 nike

我正在尝试使用 google content api 使用 php 进行购物。谷歌文档为此提供了以下代码。但最后一行 $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);

关于php - 用于购物的谷歌内容 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58016108/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com