简体   繁体   English

如何用ebay API获得价格

[英]how to get price with ebay API

So I have this code, but the price of the item isn't showing up. 所以我有这个代码,但项目的价格没有出现。 Everything else (photo and link) is working. 其他一切(照片和链接)都在工作。 I tried 'currentPrice' but nothing shows up. 我试过'currentPrice'但没有出现。 And this is the Ebay API. 这是Ebay API。 I spent about two hours looking for a solution, but it's not very well documented. 我花了大约两个小时寻找解决方案,但它没有很好的记录。

<?php
$endpoint  = 'http://svcs.ebay.com/services/search/FindingService/v1'; // URL to call
$version   = '1.11.0'; // API version supported by your application
$appid     = 'myid'; // Replace with your own AppID
$globalid  = 'EBAY-US'; // Global ID of the eBay site you want to search (e.g., EBAY-DE)
$query     = 'golf'; // You may want to supply your own query
$safequery = urlencode($query); // Make the query URL-friendly

// Construct the findItemsByKeywords HTTP GET call
$apicall = "$endpoint?";
$apicall .= "OPERATION-NAME=findItemsAdvanced";
$apicall .= "&SERVICE-VERSION=$version";
$apicall .= "&SECURITY-APPNAME=$appid";
$apicall .= "&GLOBAL-ID=$globalid";
$apicall .= "&keywords=$safequery";
$apicall .= "&paginationInput.entriesPerPage=12";
$apicall .= "&paginationInput.pageNumber=1";
$apicall .= "&categoryId=1513";

// Load the call and capture the document returned by eBay API
$resp = simplexml_load_file($apicall);

// Check to see if the request was successful, else print an error
if ($resp->ack == "Success") {
    $results = '';
    // If the response was loaded, parse it and build links
    foreach ($resp->searchResult->item as $item) {
        $pic   = $item->galleryURL;
        $link  = $item->viewItemURL;
        $title = $item->title;
        $price = $item->currentPrice;

        // For each SearchResultItem node, build a link and append it to $results
        $results .= "<div id='prod-wrap'><div class='prodimg-wrap' align='center'><img src=\"$pic\" class='prodimg'></div> <div class='prodtxt' align='center'><a href=\"$link\">$title</a></div><div class='price' align='center'><p class='price' align='center'>$price</p></div></div>";
    }
}
// If the response does not indicate 'Success,' print an error
else {
    $results = "<h3>Oops! The request was not successful. Make sure you are using a valid ";
    $results .= "AppID for the Production environment.</h3>";
}
?>
<!-- Build the HTML page with values from the call response -->
<html>
<head>
    <style type="text/css">
        body {
            font-family: arial, sans-serif;
        }

        img {
            border: none;
        }

        #store-wrap {
            width:    770px;
            height:   auto;
            position: relative;
        }

        #filter-wrap {
            width:            160px;
            float:            left;
            height:           500px;
            margin-right:     10px;
            background-color: #EBEBEB;
        }

        #result-wrap {
            width:    600px;
            float:    left;
            height:   auto;
            position: relative;
        }

        #pagination-wrap {
            width:  200px;
            float:  right;
            height: 20px;
        }

        #prod-wrap {
            width:            150px;
            height:           200px;
            margin:           0 15px 15px;
            float:            left;
            border:           1px solid #999999;
            background-color: #CCCCCC;
        }

        .prodimg-wrap {
            width: 150px;
        }

        .prodimg {
            width:   100px;
            height:  100px;
            padding: 4px;
        }

        .prodtxt {
            font-size: 11px;
            width:     130px;
            padding:   0 8px;
        }
        .price {
            font-size: 11px;
            width: 60px;
            padding: 0 8px;
        }
        .price p {
            font-size: 11px;
            color: black;
        }
    </style>
</head>
<body>

<h1><?php echo $query; ?></h1>

<table>
    <tr>
        <td>
            <div id="store-wrap">

                <div id="result-wrap">
                    <?php echo $results;?>

                </div>
            </div>
        </td>
    </tr>
</table>

</body>
</html>

You can try it with findItemsAdvanced.searchResult.item.sellingStatus 您可以使用findItemsAdvanced.searchResult.item.sellingStatus进行尝试

 $price = $item->sellingStatus->currentPrice;

searchResult.item.sellingStatus.currentPrice Amount (double)

The current price of the item given in the currency of the site on which the item is listed. 以项目所在的站点的货币给出的项目的当前价格。 That is, currentPrice is returned in the original listing currency. 也就是说,currentPrice以原始列表货币返回。

For competitive-bid item listings, currentPrice is the current minimum bid price if the listing has no bids, or the current high bid if the listing has bids. 对于竞争性投标项目列表,currentPrice是当前最低出价(如果列表没有出价),或当前高出价(如果列表具有出价)。 A Buy It Now price has no effect on currentPrice. “立即购买”价格对currentPrice没有影响。

For Basic Fixed-Price (FixedPrice), Store Inventory (StoreInventory), Ad Format (AdFormat), and Classified Ad (Classified) listings, currentPrice is the current fixed price. 对于基本固定价格(FixedPrice),商店库存(StoreInventory),广告格式(AdFormat)和分类广告(分类)列表,currentPrice是当前的固定价格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM