易趣API:获取物品购买历史记录

时间:2016-12-09 22:59:29

标签: api ebay ebay-api

基本上我需要获得此处提供的相同信息 http://offer.ebay.com/ws/eBayISAPI.dll?ViewBidsLogin&item=221864583914&rt=nc&_trksid=p2047675.l2564

根据文档,GetItemTransactions是我正在搜索的方法。我试过了,它没有给出任何交易。

以下是代码,如果您想自己测试一下(应该启用curl)

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

$token = "AgAAAA**AQAAAA**aAAAAA**D55JWA**nY+sHZ2PrBmdj6wVnY+sEZ2PrA2dj6ABlIWoAZeApg2dj6x9nY+seQ**23sDAA**AAMAAA**efeUquPbnQ2MiXisn2kcSIvJ3MOhnzuRf7V5BmJdhMLNVX11yxak3P3jIoDV58s7VAFRcYfTnaltMr3CNRBpeVFAKry+t+jTfuXAaKRfUN2z4LjNngQH5/QhJTrDsVTTEinEizj4UXnpNLXWYErZ4sEn9gGcG6jALdKbLam36m9EeBbF9ZDTUivd8MkQYXOAa3MWl3+vau06gbd9Dm3sXiMB46ainm8EvxAm+ZUEGtxCNRHTDdsuMOTzmC0Jc5IYisf2kWMSyjaFG3bruEo1WLAYsSGuixOwLtVEAZkc5MVbSoHtfv9q4HWHv0o0hOgJP/dN7eyYRhC6uclvs+fk4NyyOh3+6hSKYEcyNXdFm+9ZJmZdCieg4PtEmyrmSy2YV5M/Upqq53D9+TSfBHchfGZDCrFw3fY3RHnE1gZKnV3gaOb6lAbhDV79QDkM4Qyi3wfEQE0FzPvzDzUuADy1nEtPSRa2Koz1bR57Lvt5dc/vh0z0JLvyNVEs6wZNfDcj5mwgXvryQMMMBIOAgY/w3gEHiuyw/Z7iIV+y9h4FMHIaroeAaBpHa5JXbojkCph5Ej8KUOesjbUstZXEjBD+XdEDRSK5ThR2/T6+9N5eU1uj+7PuhoHllZhH6AKpo5tDlAzkTfU5YeK7vtV8Mb4ByHNgAA08nizMM1bc35YMmf1LS7D6gV/pNNT2t5cDXsoP6kWtcbsmwIW+XaBj+A2J7a0VxWmXvuDQI3q7+HpLgA1q35Mke5pACVE1OlOvXzOt";

function GetItemTransactions(){
    global $url, $token;
    $post = '<?xml version="1.0" encoding="utf-8"?>
        <GetItemTransactionsRequest xmlns="urn:ebay:apis:eBLBaseComponents">
          <ItemID>152343698747</ItemID>
          <RequesterCredentials>
            <eBayAuthToken>'.$token.'</eBayAuthToken>
          </RequesterCredentials>
        </GetItemTransactionsRequest>';

    $headers = array("X-EBAY-API-COMPATIBILITY-LEVEL: 967",
    "X-EBAY-API-CALL-NAME: GetItemTransactions",
    "X-EBAY-API-SITEID: 0",
    "Content-Type: text/xml");

    $result = request($url, $post, $headers);
    return json_decode(json_encode(simplexml_load_string($result)), true);
}

function request($url, $post, $headers) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    if($post){
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    }
    $result = curl_exec($ch);
    curl_close($ch);
    return $result;
}


echo "<pre>";
print_r(GetItemTransactions());
echo "</pre>";

0 个答案:

没有答案