eBay FindingAPI - findItemsByProduct,PHP

时间:2012-03-14 06:56:58

标签: php api ebay

我正在尝试将eBay API集成到我的项目中。 我使用ZendFramework并且有用于eBay FindingAPI的库,但它不适用于方法'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值。')。我尝试了不同的传递值变体,但它不起作用:(我在这里看到的传递值的当前版本:how to use python xml.etree.ElementTree to parse eBay API response?

用法:

<?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有什么问题?!

2 个答案:

答案 0 :(得分:1)

似乎您传递了错误的产品ID(itemID而不是ProductID)。 $ eBay-&GT; findByProduct( '4719331316129'); - 13位数,通常ProductId有8-9位数 比较:

<item>
  <itemId>230823026330</itemId>
  <title>Apple iPhone 3G - 8GB - Black (AT&amp;T) Smartphone #26459</title>
  <globalId>EBAY-US</globalId>
  <primaryCategory>
    <categoryId>9355</categoryId>
    <categoryName>Cell Phones &amp; 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>

答案 1 :(得分:0)

您发送的ID已被视为产品的UPC。

findItemsByProduct需要  productId

传递产品ID时必须指定

type。 类型可以包括ISBN,UPC,EAN或ReferenceID(ePID)。

在您的情况下,您传递的ID被视为UPC号码。因此,请确认UPC是否适用于该产品。

相关问题