php - Google Content API for Shopping:创建货件时出错
问题描述
我希望在 Google 购物中将订单标记为已发货,但对如何格式化lineItems
. 我正在关注运输订单项的官方文档:
https://developers.google.com/shopping-content/v2/reference/v2.1/orders/shiplineitems
这是我的代码:
$client = new Google_Client();
$service = new Google_Service_ShoppingContent($client);
// Get Order and Line Items
$order = $service->orders->get('MERCHANT-ID', 'ORDER-ID', array());
$lineItems = $order->getLineItems();
// Prepare Item Info
foreach($lineItems as $item) {
$items = array('lineItemId' => $item->getId(),'productId' => $item->getProduct()->getId(), 'quantity' => $item->quantityPending);
}
// Prepare Shipment Info
$shipment = array('shipmentId' => 'xxx', 'carrier' => 'ups', 'trackingId' => '1234567890');
// Prepare PostBody
$postBody = new Google_Service_ShoppingContent_OrdersShipLineItemsRequest();
$postBody->operationId = rand();
$postBody->lineItems = $items;
$postBody->shipmentInfos = $shipment;
// Mark Google Order as Shipped
$service->orders->shiplineitems('MERCHANT-ID', 'ORDER-ID', $postBody, array());
这会产生以下错误,但我无法弄清楚到底出了什么问题:
Google_Service_Exception: { "error": { "errors": [ { "domain": "global", "reason": "invalid", "message": "lineItems 的值无效:{lineItemId=HI2PTRMVLNCZEXP, productId=online:en :US:d3k3245, quantity=2}", "locationType": "other", "location": "" } ], "code": 400, "message": "lineItems 的值无效:{lineItemId=HI2PTRMVLNCZEXP, productId =online:en:US:d3k3245, 数量=2}" } }
任何想法我做错了什么?
解决方案
API 需要一个 Google_Service_ShoppingContent_OrderShipmentLineItemShipment 类的数组。
$lineItemShipments = array();
$lineItemShipment = new Google_Service_ShoppingContent_OrderShipmentLineItemShipment();
$lineItemShipment->setLineItemId($item->getId());
$lineItemShipment->setQuantity($item->quantityPending);
$lineItemShipments[] = $lineItemShipment;
$postBody->setLineItems($lineItemShipments);
推荐阅读
- android - 当我尝试为我正在通过 Unity 开发的游戏构建 apk 文件时,Android SDK 未正确安装错误?
- gcc - 如何以及何时在 AArch64 上使用 -mbig-endian gcc 选项?
- amazon-web-services - `aws 记录 list-tags-log-group` 时出错
- python - 使用 Python 在两台计算机之间发送数字
- java - 使用 JSP 和 POM 中的自定义父集从 Spring Boot MVC 项目中创建一个可执行的 jar 服务内容
- android - Google Places API + ReactNative
- google-bigquery - 如何在 bigQuery 中查询特定产品的每日费用?
- bash - 提取/剪切字符串匹配的行
- algorithm - 给定时间的路线规划器
- angular - 如何将布尔值更改为 mat 复选框的字符串?(Angular 材质)