0

我正在尝试将 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 怎么了?!

4

2 回答 2

1

似乎您传递了不正确的产品 ID(itemID 而不是 ProductID)。$eBay->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>
于 2012-07-10T15:13:51.990 回答
0

您发送的 Id 被视为产品的 UPC。

findItemsByProduct 需要 productId

传递产品 ID 时必须指定类型。类型可以包括 ISBN、UPC、EAN 或 ReferenceID (ePID)。

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

于 2017-11-23T12:57:04.407 回答