0

プロジェクトに 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 を変更すれば、すべて OK です。EBAY-US の何が問題なのですか?!

4

2 に答える 2

1

間違った製品 ID (ProductID ではなく itemID) を渡したようです。$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 に答える