Ebay - Shopping API

Heinz Schrot

Mitglied
Hallo zusammen,

hat jemand schon Erfahrung sammeln können mit oben genannter API?

Ich hatte den sample Code mal ausprobiert:

PHP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

<?php

require_once('DisplayUtils.php');  // functions to aid with display of information

//error_reporting(E_ALL);  // turn on all errors, warnings and notices for easier debugging

if(isset($_POST['SellerID']))
{
    $endpoint = 'http://open.api.ebay.com/shopping';  // URL to call
    $responseEncoding = 'XML';   // Format of the response 
    $version = '537';   // API version number
    $appID   = 'INSERT_YOUR_APP_ID';   // replace this with your AppID
    
    $debug   = true;
    $debug = (boolean) $_POST['Debug']; 

    $sellerID  = urlencode($_POST['SellerID']);   // cleanse input
    $siteID    = urlencode($_POST['SiteID']);  

    $pageResults = '';
    $pageResults .= getUserProfileResultsAsHTML($sellerID);
    $pageResults .= getFindItemsAdvancedResultsAsHTML($sellerID);

} // if    


function getUserProfileResultsAsHTML($sellerID) {
    global $siteID, $endpoint, $responseEncoding, $version, $appID, $debug;
    $results = '';
    
    $apicall = "$endpoint?callname=GetUserProfile"
             . "&version=$version"
             . "&siteid=$siteID"
             . "&appid=$appID"
             . "&UserID=$sellerID"
             . "&IncludeSelector=Details,FeedbackHistory"   // need Details to get MyWorld info
             . "&responseencoding=$responseEncoding";
             
    if ($debug) { print "<br />GetUserProfile call = <blockquote>$apicall </blockquote>"; }
    
    // Load the call and capture the document returned by the Shopping API
    $resp = simplexml_load_file($apicall);
    
    if ($resp) {
        if (!empty($resp->User->MyWorldLargeImage)) {
            $myWorldImgURL = $resp->User->MyWorldLargeImage;
        } else {
            $myWorldImgURL = 'http://pics.ebaystatic.com/aw/pics/community/myWorld/imgBuddyBig1.gif';            
        }
        $results .= "<table><tr>\n";
        $results .= "<td><a href=\"" . $resp->User->MyWorldURL . "\"><img src=\"" 
                  . $myWorldImgURL . "\"></a></td>\n";
        $results .= "<td>Seller : $sellerID <br /> \n";
        $results .= "Feedback score : " . $resp->User->FeedbackScore . "<br />\n";
        $posCount = $resp->FeedbackHistory->UniquePositiveFeedbackCount;
        $negCount = $resp->FeedbackHistory->UniqueNegativeFeedbackCount;
        $posFeedBackPct = sprintf("%01.1f", (100 * ($posCount / ($posCount + $negCount))));
        $results .= "Positive feedback : $posFeedBackPct%<br />\n";
        $regDate = substr($resp->User->RegistrationDate, 0, 10);
        $results .= "Registration date : $regDate<br />\n";
        
        $results .= "</tr></table>\n";
                  
    } else {
        $results = "<h3>No user profile for seller $sellerID";
    }
    return $results;
} // function



function getFindItemsAdvancedResultsAsHTML($sellerID) {
    global $siteID, $endpoint, $responseEncoding, $version, $appID, $debug;
    
    $maxEntries = 3;
    
    $itemType  = urlencode($_POST['ItemType']);
    $itemSort  = urlencode($_POST['ItemSort']);
    
    $results = '';   // local to this function
    // Construct the FindItems call 
    $apicall = "$endpoint?callname=FindItemsAdvanced"
             . "&version=$version"
             . "&siteid=$siteID"
             . "&appid=$appID"   // replace this with your AppID
             . "&SellerID=$sellerID"
             . "&MaxEntries=$maxEntries"
             . "&ItemSort=$itemSort"
             . "&ItemType=$itemType"
             . "&IncludeSelector=SearchDetails"             // to get Converted Price
             . "&trackingpartnercode=9"              // fill in your information in next 3 lines
             . "&trackingid=123456789"
             . "&affiliateuserid=456"
             . "&responseencoding=$responseEncoding";
             
    if ($debug) { print "<br />FindItemsAdvanced call = <blockquote>$apicall </blockquote>"; }
    
    // Load the call and capture the document returned by the Shopping API
    $resp = simplexml_load_file($apicall);
    
    // Check to see if the response was loaded, else print an error
    if ($resp->SearchResult->ItemArray) {
        $results .= 'Total items : ' . $resp->TotalItems . "<br />\n";
        $results .= '<table id="example" class="tablesorter" border="0" cellpadding="0" cellspacing="1">' . "\n";
        $results .= "<thead><tr><th /><th>Title</th><th>Price &nbsp; &nbsp; </th><th>Shipping &nbsp; &nbsp; </th><th>Total &nbsp; &nbsp; </th><th><!--Currency--></th><th>Time Left</th><th>End Time</th></tr></thead>\n";
        
        // If the response was loaded, parse it and build links  
        foreach($resp->SearchResult->ItemArray->Item as $item) {
            if ($item->GalleryURL) {
                $picURL = $item->GalleryURL;
            } else {
                $picURL = "http://pics.ebaystatic.com/aw/pics/express/icons/iconPlaceholder_96x96.gif";
            }
            $link  = $item->ViewItemURLForNaturalSearch;
            $title = $item->Title;
            
            $price = sprintf("%01.2f", $item->ConvertedCurrentPrice);
            $ship  = sprintf("%01.2f", $item->ShippingCostSummary->ShippingServiceCost);
            $total = sprintf("%01.2f", ((float)$item->ConvertedCurrentPrice 
                                      + (float)$item->ShippingCostSummary->ShippingServiceCost));
            
            // Determine currency to display - so far only seen cases where priceCurr = shipCurr, but may be others
            $priceCurr = (string) $item->ConvertedCurrentPrice['currencyID'];
            $shipCurr  = (string) $item->ShippingCostSummary->ShippingServiceCost['currencyID'];
            if ($priceCurr == $shipCurr) {
                $curr = $priceCurr;
            } else {
                $curr = "$priceCurr / $shipCurr";  // potential case where price/ship currencies differ
            }

            $timeLeft = getPrettyTimeFromEbayTime($item->TimeLeft);
            $endTime = strtotime($item->EndTime);   // returns Epoch seconds
            $endTime = $item->EndTime;
               
            $results .= "<tr><td><a href=\"$link\"><img src=\"$picURL\"></a></td><td><a href=\"$link\">$title</a></td>"
                     .  "<td>$price</td><td>$ship</td><td>$total</td><td>$curr</td><td>$timeLeft</td><td><nobr>$endTime</nobr></td></tr>";
        }
        $results .= "</table>";
    }
    // If there was no search response, print an error
    else {
        $results = "<h3>No items found matching the $itemType type.";
    }  // if resp
    
    return $results;
    
}  // function


?>



<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>GetUserProfile</title>
<script src="./js/jQuery.js"></script>
<script src="./js/jQueryUI/ui.tablesorter.js"></script>

<script>
    $(document).ready(function() { 
        $("table").tablesorter({ 
            sortList:[[7,0],[4,0]],      // upon screen load, sort by col 7, 4 ascending (0)
            debug: false,                // if true, useful to debug Tablesorter issues
            headers: { 
                0: { sorter: false },    // col 0 = first = left most column - no sorting
                5: { sorter: false }, 
                6: { sorter: false },
                7: { sorter: 'text'}     // specify text sorter, otherwise mistakenly takes shortDate parser
            } 
        }); 
    });
</script>
  
</head>

<body>


<link rel="stylesheet" href="./css/flora.all.css" type="text/css" media="screen" title="Flora (Default)">

<form action="GetUserProfileFIA.php" method="post">
<table cellpadding="2" border="0">
    <tr>
        <th>SellerID</th>
        <th>SiteID</th>
        <th>ItemType</th>
        <th>ItemSort</th>
        <th>Debug</th>
    </tr>    
    <tr>
        <td><input type="text" name="SellerID" value=""></td>
        <td>
            <select name="SiteID">
                <option value="15">Australia - 15 - AUD</option>
                <option value="2">Canada - 2 - CAD</option>
                <option value="77">Germany - 77 - EUR</option>
                <option value="3">United Kingdom - 3 - GBP</option>
                <option selected value="0">United States - 0 - USD</option>
            </select>
        </td>
        <td>
            <select name="ItemType">
                <option selected value="AllItemTypes">AllItemTypes</option>
                <option value="AuctionItemsOnly">AuctionItemsOnly</option>
                <option value="FixedPricedItem">FixedPricedItem</option>
                <option value="StoreInventoryOnly">StoreInventoryOnly</option>
            </select>
        </td>
        <td>
            <select name="ItemSort">
                <option value="BidCount">BidCount</option>
                <option selected value="EndTime">EndTime </option>
                <option value="PricePlusShipping">PricePlusShipping</option>
                <option value="CurrentBid">CurrentBid</option>
            </select>
        </td>
        <td>
        <select name="Debug">
            <option value="1">true</option>
            <option selected value="0">false</option>
            </select>
        </td>
        
    </tr>
    <tr>
        <td colspan="4" align="center"><INPUT type="submit" name="submit" value="Search"></td>
    </tr>
</table>
</form>

<?php 
    print $pageResults;
    $allItemsURL = "http://search.ebay.com/_W0QQsassZ" . $sellerID;
    print "<p><a href=\"$allItemsURL\">See all items from this seller</a></p>";
?>

</body>
</html>

Aber ich kam auf max ca.100 Ergebnisse, obwohl ca. 1000 eingestellt sind.

Kann ich mit meinem API key nicht mehr als 100 Ergebnisse ausgeben, oder ist da ein Weg um an mehr als die 100 Ergebnisse zu kommen.

Haben Programme wie "Baywotch" eine andere API/API-Key um ausführliche/weitreichende Abfragen an Ebay zu senden?

Mich würde eine Analyse wie die "Ebay suche" und die "Verkäufer Suche" in Baywotch interessieren. Ob sowas mit den in http://developer.ebay.com/Default.aspx vorhandenen APIs in PHP möglich ist?

Grüße
 
Laut der API darf MaxEntries einen Wert von maximal 100 betragen.

Man könnte nun einfach die "PageNumbers" durchgehen und somit alle Suchergebnisse auslesen - denke ich.

Wäre zumindest meine spontane Idee dazu, bis auf die 3 Minuten eben habe ich mich noch nicht mit der API von eBay auseinander gesetzt. ;)
 
Zurück