从ebay类别api

时间:2015-10-29 06:36:26

标签: xml api response categories ebay

我正在以XML格式获取响应易趣类别数据,因此我无法读取xml响应。它返回许多类别及其子级别。如何读取xml响应?任何伎俩?

<?php 
       $app_id="xxxxxxx";
       $dev_id ="xxxxxxx";
       $cert_id="xxxxxxx";
       $call_name="GetCategoryInfoRequest";
       $token="xxxxxxxx";
       $site_id = 0;
       $compat_level=819;

    $endpoint = "https://api.ebay.com/ws/api.dll";



        $headers = array(
            'X-EBAY-API-COMPATIBILITY-LEVEL: 819',
            'X-EBAY-API-DEV-NAME: '.$dev_id,
            'X-EBAY-API-APP-NAME: '.$app_id,
            'X-EBAY-API-CERT-NAME: '.$cert_id,
            'X-EBAY-API-CALL-NAME: GetCategories',
            'X-EBAY-API-OPERATION-NAME: GetCategories',
            'X-EBAY-API-RESPONSE-ENCODING:JSON',
            'X-EBAY-API-SITEID: 0',
            'Content-Type:text/XML'
        );

        $xmlRequest = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
        $xmlRequest .= "<GetCategoriesRequest xmlns=\"urn:ebay:apis:eBLBaseComponents\">";
        $xmlRequest .= "<RequesterCredentials>";
        $xmlRequest .= "<eBayAuthToken>{$token}</eBayAuthToken>";
        $xmlRequest .= "</RequesterCredentials>";
        $xmlRequest .= "<CategorySiteID>0</CategorySiteID>";
        $xmlRequest .= "<DetailLevel>ReturnAll</DetailLevel>";
        $xmlRequest .= "</GetCategoriesRequest>";



$connection = curl_init();
curl_setopt($connection, CURLOPT_URL, $endpoint);
curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($connection, CURLOPT_HTTPHEADER, $headers);
curl_setopt($connection, CURLOPT_POST, 1);
curl_setopt($connection, CURLOPT_TIMEOUT, 400000);
curl_setopt($connection, CURLOPT_POSTFIELDS, $xmlRequest);
curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($connection);
curl_close($connection);
print_r($response);
?>

返回未格式化的行数,请查看以下易趣类别XML响应数据

  

2015-09-09T10:24:56.505ZSuccess933E933_CORE_APICATALOG_17621198_R1truetrue200811Antiques20081truetrue379032Antiquities20081truetrue379083The   Americas37903truetruetrue1629223Byzantine37903truetruetrue1629233Celtic37903truetruetrue379053Egyptian37903truetruetrue1629163Far   Eastern37903truetruetrue379063Greek37903truetruetrue1629173Holy   Land37903truetruetrue1629183Islamic37903truetruetrue911013Near   Eastern37903truetruetrue668343Neolithic&amp;   Paleolithic37903truetruetrue379073Roman37903truetruetrue1629193South   Italian37903truetruetrue1629203Viking37903truetruetrue1629213Reproductions37903truetruetrue1711693Price   指南&amp; Publications37903truetruetrue734643Other   古物37903truetruetrue47072Architectural&amp;   Garden20081truetrue1629253Balusters4707truetruetrue1629263Barn   Doors4707truetruetrue1629273Beams4707truetruetrue379093Ceiling   Tins4707truetruetrue635163Chandeliers,Fixtures,   Sconces4707truetruetrue1629283Columns&amp;   Posts4707truetruetrue1629293Corbels4707truetruetrue379103Doors4707truetruetrue635173Finials4707truetruetrue635183Fireplaces   &安培;   Mantels4707truetruetrue47083Garden4707truetruetrue379113Hardware4707truetrue379124Door   贝尔斯&amp; Knockers37911truetruetrue379144Door Knobs&amp;   Handles37911truetruetrue379164Door Plates&amp;   Backplates37911truetruetrue1629334Drawer   Pulls37911truetruetrue1629344Ecutcheons&amp;关键孔   Covers37911truetruetrue1629354Heating Grates&amp;   Vents37911truetruetrue379134Hooks&amp;   Brackets37911truetruetrue379154Locks&amp; Keys37911truetruetrue1629304

1 个答案:

答案 0 :(得分:0)

您似乎感到困惑 - 并且在两个不同的eBay API调用之间混合代码:

除非您特别需要使用Trading API,否则我建议您选择GetCategoryInfo并使用该调用。您不需要POST标头,而是可以在REST / GET请求中构建所有参数。