Help with Ebay Developer API code

Discussion in 'Programming' started by mnymkr, Feb 16, 2008.

  1. #1
    Here is the code I am using to call a seach from ebay and display products. It is borrowed from 45n5.com

    1) Anyhoo, I am not sure what search it is actually calling. I can tell it isn't latest items , maybe most popular, random I am not sure.

    2) Some of the pictures do not show. I see it is calling gallery pic, how can I make it call whatever picture is there?

    <?php
    
      ///do ebay stuff
    
    ///ebay variables 
    
    //
    
    //
    
    //
    
    $RequestToken = '7i80MZdNpSU%3D**ttEOMfJUQZnfmhhGr7EGYOx6uRU%3D';  // ebay REST token, needed with REST calls
    
    $RequestUserId = 'xxxxx;  // eBay User ID, needed with REST calls
    
    $pid="xxxxxx"; //your ebay pid
    
    $aid="xxxxx"; //your ebay aid 
    
    
    
    $SiteId = '0';  // Site used. Site ID 0 = US
    
    $Version = '497'; // API version
    
    
    
    
    
    
    
    
    
    
    
    $date=date(U); // format date for calculation in seconds
    
    $hourdiff = "15"; //change the server time plus one hour
    
    $timeadjust = ($hourdiff * 60 * 60); //this is how to calc it
    
    $adjtimeleft = date("Y-m-d", $date + $timeadjust); //format display
    
    $adjtimeright = date("H:m:s", $date + $timeadjust); //format display
    
    
    
    $endtimefrom = "&EndTimeFrom=" . $adjtimeleft . "T" . $adjtimeright . ".000Z";//2007-08-04T18:20:27.000Z";
    
    
    
    
    
    
    
    
    
    // Construct the GetSearchResults REST call 
    
    $apicall = "http://rest.api.ebay.com/restapi?CallName=GetSearchResults&RequestToken=" . $RequestToken . "&RequestUserId=" . $RequestUserId . "&SiteId=$SiteId&Version=$Version&Query=$SafeQuery&EntriesPerPage=$EntriesPerPage&PageNumber=$PageNumber&UnifiedInput=1$endtimefrom";
    
    
    
    // Load the call and capture the XML document returned by eBay API as an object
    
    
    
    		//Initialize the Curl session
    
    $ch = curl_init();
    
    
    
    //Set curl to return the data instead of printing it to the browser.
    
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    
    //Set the URL
    
    curl_setopt($ch, CURLOPT_URL, $apicall);
    
    //Execute the fetch
    
    $data = curl_exec($ch);
    
    //Close the connection
    
    curl_close($ch);	
    
    		
    
    		
    
        $xml = new SimpleXMLElement($data);
    
    
    
    // Check to see if the XML response was loaded, else print an error
    
    
    
    
    
    
    
    if ($xml->SearchResultItemArray->SearchResultItem) {
    
    $contentcenter.="<h1>Auctions for " .   $title  . "</h1>";
    
    
    
    	$results = '';
    
    
    
    	// If the XML response was loaded, parse it and build links 
    
    	foreach ($xml->SearchResultItemArray->SearchResultItem as $searchitem) {
    
    		$link  = $searchitem->Item->ListingDetails->ViewItemURL . "&pid=$pid&aid=$aid";
    
    		$title = $searchitem->Item->Title;
    
            $pic=$searchitem->Item->PictureDetails->GalleryURL;
    
    		// For each SearchResultItem node, build a link and append it to $results
    
    		$results .="<div style=\"margin-bottom:20px;border:1px solid #f1f1f1;\">";
    
    
    
    		if (empty($pic)) {
    
    		$results .="\n<img src=\"pic.jpg\" alt=\"\" style=\"float:left;\" />";
    
    		}else{
    
    		$results .="\n<img src=\"$pic\" alt=\"\" style=\"float:left;\" />";
    
    		}
    
    		
    
    		$results .= "<a href=\"$link\">$title</a><div style=\"clear:both\"></div>";
    
    		// For each SearchResultItem node, build a link and append it to $results
    
    		$results .= "<div style=\"clear:both\"></div></div>";
    
    
    
    	}
    
    }
    
    // If there was no XML response, print an error
    
    else {
    
    	//$results = "Dang! Must not have got the XML response!";
    
    }
    
    $contentcenter.=$results;
    
    
    
    
    
    
    
    ?>
    
    
    
    <?php echo $contentcenter; ?>
    
    Code (markup):
     
    mnymkr, Feb 16, 2008 IP