我正在尝试将易趣API集成到我的项目中。我使用ZendFramework,并且有易趣查找API的库,但它不适用于方法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解析易趣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怎么了?!
似乎您传递了不正确的产品ID(itemID而不是ProductID)。$eBay->findByProduct('4719331316129');-13位,而ProductId通常为8-9位比较:
<item>
<itemId>230823026330</itemId>
<title>Apple iPhone 3G - 8GB - Black (AT&T) Smartphone #26459</title>
<globalId>EBAY-US</globalId>
<primaryCategory>
<categoryId>9355</categoryId>
<categoryName>Cell Phones & Smartphones</categoryName>
</primaryCategory>
<galleryURL>http://thumbs3.ebaystatic.com/pict/2308230263304040_1.jpg</galleryURL>
<viewItemURL>http://www.ebay.com/itm/Apple-iPhone-3G-8GB-Black-AT-T-Smartphone-26459-/230823026330?pt=Cell_Phones</viewItemURL>
<productId type="ReferenceID">101892398</productId>
您发送的Id被视为产品的UPC。
findItemsByProduct需要productId
传递产品id时必须指定类型。类型可以包括ISBN、UPC、EAN或ReferenceID(ePID)。
在您的情况下,您通过的身份证被视为UPC号码。因此,请确认UPC是否适用于该产品。