XT Knowledge Base
Hauptseite | Über | Hilfe | FAQ | Spezialseiten | Anmelden

Druckversion | Impressum | Datenschutz | Aktuelle Version

Ebay PHP API

(Unterschied zwischen Versionen)

(Die Seite wurde neu angelegt: „<pre> <? class EbayItemInfo { public $title; public $link; public $bids; public $price; public $timeleft; …“)
 
(Der Versionsvergleich bezieht 2 dazwischenliegende Versionen mit ein.)
Zeile 8: Zeile 8:
         public $price;
         public $price;
         public $timeleft;
         public $timeleft;
-
        public $ack;
 
          
          
         function __construct( $xml )
         function __construct( $xml )
Zeile 14: Zeile 13:
             if( $xml === false )
             if( $xml === false )
             {
             {
-
                 $this->title = "Invalid Article-ID";
+
                 $this->title = "Invalid Request";
                 $this->link = "http://ebay.de";
                 $this->link = "http://ebay.de";
                 return;
                 return;
Zeile 26: Zeile 25:
             }
             }
              
              
-
        $this->ack = $xml->Ack;
 
             $this->title = $xml->Item->Title;
             $this->title = $xml->Item->Title;
             $this->link = $xml->Item->ViewItemURLForNaturalSearch;
             $this->link = $xml->Item->ViewItemURLForNaturalSearch;

Aktuelle Version vom 16:09, 12. Aug. 2010

<?
    class EbayItemInfo
    {
        public $title;
        public $link;
        public $bids;
        public $price;
        public $timeleft;
        
        function __construct( $xml )
        {
            if( $xml === false )
            {
                $this->title = "Invalid Request";
                $this->link = "http://ebay.de";
                return;
            }
            
            if( $xml->Ack != "Success" )
            {
                $this->title = $xml->Errors->ShortMessage;
                $this->link = "http://ebay.de";
                return;                
            }
            
            $this->title = $xml->Item->Title;
            $this->link = $xml->Item->ViewItemURLForNaturalSearch;
            $this->bids = $xml->Item->BidCount;
            $this->price = sprintf( "%.2f €", $xml->Item->ConvertedCurrentPrice );
            $this->timeleft = $xml->Item->TimeLeft;
        }
    }
    
    class EbayRequest
    {
        private $_appid;
        private $_ebayurl;
        
        function __construct( $appid, $ebayurl )
        {
            $this->_appid = $appid;
            $this->_ebayurl = $ebayurl;
        }
        
        function createParamList( $data )
        {
            $req = "";
            foreach( $data as $key => $value )
                $req .= $key . '=' . $value . '&';
        
            return substr( $req, 0, strlen($req)-1 );
        }        
        
        function getItemInfo( $itemid )
        {   
            $data = array(  
                'callname' => 'GetSingleItem',
                'responseencoding' => 'XML',
                'appid' => $this->_appid,
                'siteid' => 77,
                'version' => 515,
                'ItemID' => $itemid
            );

            $params = $this->createParamList( $data );
            
            $url = $this->_ebayurl.'?'.$params;
            
            $file = file_get_contents( $url );
            if( $file === false )
                return false;
                
            $xml = new SimpleXMLElement( $file );
            return new EbayItemInfo( $xml );           
        }
    };

    /*    
    $ebay = new EbayRequest( $_CFG['EBAY_APPID'], $_CFG['EBAY_URL'] );
    $result = $ebay->getItemInfo( '320572036895' );
    print_r( $result );
    */
?>