我正在尝试将 eBay API 集成到我的项目中。我使用 ZendFramework 并且有 eBay FindingAPI 的库,但它不适用于 method findItemsByProduct
。
为了理解问题,我写了我的小班:
<?php
class MyProject_Model_Ebay
{
const FINDING_API_URL = 'http://svcs.ebay.com/services/search/FindingService/v1?';
private $appId;
public function __construct($appId)
{
$this->appId = $appId;
}
public function findByProduct($id, $type = 'UPC')
{
$params = array(
'productId.@type' => $type,
'productId' => $id,
);
return $this->doApiRequest('findItemsByProduct', $params);
}
public function findByKeywords($keywords)
{
$params = array(
'keywords' => $keywords,
);
return $this->doApiRequest('findItemsByKeywords', $params);
}
private function doApiRequest($operationName, $payload)
{
$global = array(
'OPERATION-NAME' => $operationName,
'SECURITY-APPNAME' => $this->appId,
'GLOBAL-ID' => 'EBAY-US',
'SERVICE-VERSION' => '1.0.0',
'MESSAGE-ENCODING' => 'UTF-8',
'RESPONSE-DATA-FORMAT' => 'JSON',
);
$ret = file_get_contents(
self::FINDING_API_URL . http_build_query($global) . '&REST-PAYLOAD&' . http_build_query($payload)
);
return $ret;
}
}
方法findItemsByKeywords
工作正常,但findItemsByProduct
仍然返回错误
无效的产品 ID 值。
我尝试了不同的传递值变体,但它不起作用:(我在这里看到的传递值的当前版本:如何使用 python xml.etree.ElementTree 解析 eBay API 响应?
用法:
<?php
$eBay = new MyProject_Model_Ebay(
'My-app-id'
);
$eBay->findByProduct('4719331316129');
回复:
{"findItemsByProductResponse":[{"ack":["Failure"],"errorMessage":[{"error":[{"errorId":["41"],"domain":["Marketplace"],"severity":["Error"],"category":["Request"],"message":["Invalid product ID value."],"subdomain":["Search"],"parameter":["4719331316129"]}]}],"version":["1.11.1"],"timestamp":["2012-03-14T06:41:42.600Z"]}]}
重要的!例如,如果我在 EBAY-DE 上更改 GLOBAL-ID,一切正常!EBAY-US 怎么了?!