本文介绍了易趣FindingAPI - findItemsByProduct,PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想给eBay API在我的项目整合。
我用ZendFramework和有库易趣FindingAPI,但它不适用于方法'findItemsByProduct'。工作

有关问题的理解我写我的小类:

 < PHP
类MyProject_Model_Ebay
{
    常量FINDING_API_URL ='?http://svcs.ebay.com/services/search/FindingService/v1';    私人$ APPID;    公共职能__construct($ APPID)
    {
        $这个 - >的appid = $ APPID;
    }    公共职能findByProduct($ ID,$ TYPE =UPC)
    {
        $ PARAMS =阵列(
            '的productId @型'=> $型,
            '的productId'=> $ ID,
        );        返回$这个 - > doApiRequest('findItemsByProduct',$ params)方法;
    }    公共职能findByKeywords($关键字)
    {
        $ PARAMS =阵列(
            '关键字'=> $关键字,
        );        返回$这个 - > doApiRequest('findItemsByKeywords',$ params)方法;
    }
    私有函数doApiRequest($ operationName,$有效载荷)
    {        $ =全球阵列(
            操作-NAME => $ operationName,
            安全-APPNAME'=> $这个 - > APPID,
            GLOBAL-ID'=> EBAY-US,
            SERVICE-VERSION'=> 1.0.0,
            消息编码'=> UTF-8,
            响应数据格式'=> JSON,
        );        $ RET =的file_get_contents(
            自:: FINDING_API_URL。 http_build_query($全局)。 '和; REST的有效载荷放大器;' 。 http_build_query($负载)
        );        返回$ RET;
    }}

方法'findItemsByKeywords工程确定,但findItemsByProduct仍返回错误(无效的产品ID值。')。我试图传递价值的不同变体,但它不工作,传递价值,我看到这里的:(当前版本:how使用Python位置为xml.etree.ElementTree解析易趣API响应?

用法:

 < PHP
$易趣=新MyProject_Model_Ebay(
    我-APP-ID
);$ eBay-> findByProduct('4719331316129');

响应:

<$p$p><$c$c>{\"findItemsByProductResponse\":[{\"ack\":[\"Failure\"],\"errorMessage\":[{\"error\":[{\"errorId\":[\"41\"],\"domain\":[\"Marketplace\"],\"severity\":[\"Error\"],\"category\":[\"Request\"],\"message\":[\"Invalid产品ID value.\"],\"subdomain\":[\"Search\"],\"parameter\":[\"4719331316129\"]}]}],\"version\":[\"1.11.1\"],\"timestamp\":[\"2012-03-14T06:41:42.600Z\"]}]}

重要!
如果我改变EBAY-DE GLOBAL-ID,例如,一切OK!这有什么错EBAY-US?!


解决方案

看来你已经通过不正确的产品ID(itemid的,而不是产品ID)。
$ eBay-> findByProduct('4719331316129'); - 13位数字,通常当有产品编号8-9位数字
比较:

 &LT;项目&GT;
  &LT;&的itemId GT; 230823026330&LT; /&的itemId GT;
  &LT;标题&GT;苹果iPhone 3G - 8GB - 黑色(AT&安培; amp; T公司)智能手机#26459&LT; /标题&GT;
  &LT; globalId&GT; EBAY-US&LT; / globalId&GT;
  &LT; primaryCategory&GT;
    &LT;&的categoryId GT; 9355&LT; /&的categoryId GT;
    &LT;类别名称&GT;手机及放大器;放大器;智能手机&LT; /类别名称&GT;
  &LT; / primaryCategory&GT;
  &LT;&GALLERYURL GT; HTTP://thumbs3.ebaystatic.com/pict/2308230263304040_1.jpg< / GALLERYURL&GT;
  <viewItemURL>http://www.ebay.com/itm/Apple-iPhone-3G-8GB-Black-AT-T-Smartphone-26459-/230823026330?pt=Cell_Phones</viewItemURL>
  &LT; productId参数类型=ReferenceID&GT; 101892398&LT; /&的productId GT;

I'm trying to integrate eBay API in my project.I use ZendFramework and there is library for eBay FindingAPI, but it doesn't work for method 'findItemsByProduct'.

For understanding problem i wrote my small class:

<?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;
    }

}

Method 'findItemsByKeywords' works Ok, but 'findItemsByProduct' still returns error ('Invalid product ID value.'). I tried different variants of passing value, but it doesn't work :( Current version of passing value I saw here: how to use python xml.etree.ElementTree to parse eBay API response?

Usage:

<?php
$eBay = new MyProject_Model_Ebay(
    'My-app-id'
);

$eBay->findByProduct('4719331316129');

Response:

{"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"]}]}

Important!If i change GLOBAL-ID on EBAY-DE, for example, everything is OK! What's wrong with EBAY-US?!

解决方案

Seems that you had passed incorrect product ID (itemID instead of ProductID). $eBay->findByProduct('4719331316129'); - 13 digits, when normally ProductId has 8-9 digitsCompare:

<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>

这篇关于易趣FindingAPI - findItemsByProduct,PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 10:16