Ebay php api Finding API: Finding Items by Keywords (Does not parse the php code correctly and return data)
So I’m fairly new to web development and I’m running PHP & HTML code that constructs an eBay Finding API endpoint and then parses through the returned XML data and displays it on the webpage.
However, when the code is run on the webserver, it does not appear to run the PHP code correctly and displays a block of the PHP code as if the code is not encapsulated correctly. see image below .
I have the latest version of PHP (7.2.24) installed on the webserver. Also you should know that the code being run is standard as posted to the eBay tutorial webpage >> https://developer.ebay.com/DevZone/finding/HowTo/GettingStarted_PHP_NV_XML/GettingStarted_PHP_NV_XML.html <<. The only thing I’ve added in is my App Key.
Thanking everybody in advance for the help and assistance.
Please see code below and xml response (not filtered) >>
<?php error_reporting(E_ALL); // Turn on all errors, warnings and notices for easier debugging // API request variables $endpoint = 'http://svcs.ebay.com/services/search/FindingService/v1'; // URL to call $version = '1.0.0'; // API version supported by your application $appid = 'MyAppID'; // Replace with your own AppID $globalid = 'EBAY-US'; // Global ID of the eBay site you want to search (e.g., EBAY-DE) $query = 'harry potter'; // You may want to supply your own query $safequery = urlencode($query); // Make the query URL-friendly $i = '0'; // Initialize the item filter index to 0 // Create a PHP array of the item filters you want to use in your request $filterarray = array( array( 'name' => 'MaxPrice', 'value' => '25', 'paramName' => 'Currency', 'paramValue' => 'USD'), array( 'name' => 'FreeShippingOnly', 'value' => 'true', 'paramName' => '', 'paramValue' => ''), array( 'name' => 'ListingType', 'value' => array('AuctionWithBIN','FixedPrice','StoreInventory'), 'paramName' => '', 'paramValue' => ''), ); // Generates an indexed URL snippet from the array of item filters function buildURLArray ($filterarray) { global $urlfilter; global $i; // Iterate through each filter in the array foreach($filterarray as $itemfilter) { // Iterate through each key in the filter foreach ($itemfilter as $key =>$value) { if(is_array($value)) { foreach($value as $j => $content) { // Index the key for each value $urlfilter .= "&itemFilter($i).$key($j)=$content"; } } else { if($value != "") { $urlfilter .= "&itemFilter($i).$key=$value"; } } } $i++; } return "$urlfilter"; } // End of buildURLArray function // Build the indexed item filter URL snippet buildURLArray($filterarray); // Construct the findItemsByKeywords HTTP GET call $apicall = "$endpoint?"; $apicall .= "OPERATION-NAME=findItemsByKeywords"; $apicall .= "&SERVICE-VERSION=$version"; $apicall .= "&SECURITY-APPNAME=$appid"; $apicall .= "&GLOBAL-ID=$globalid"; $apicall .= "&keywords=$safequery"; $apicall .= "&paginationInput.entriesPerPage=3"; $apicall .= "$urlfilter"; // 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; // For each SearchResultItem node, build a link and append it to $results $results .= "<tr><td><img src=\"$pic\"></td><td><a href=\"$link\">$title</a></td></tr>"; } } // 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> <title>eBay Search Results for <?php echo $query; ?></title> <style type="text/css">body { font-family: arial,sans-serif;} </style> </head> <body> <h1>eBay Search Results for <?php echo $query; ?></h1> <table> <tr> <td> <?php echo $results;?> </td> </tr> </table> </body> </html> Unfiltered XML Response : <findItemsByKeywordsResponse xmlns="http://www.ebay.com/marketplace/search/v1/services"> <ack>Success</ack> <version>1.13.0</version> <timestamp>2020-07-01T11:59:55.672Z</timestamp> <searchResult count="3"> <item> <itemId>132883277485</itemId> <title>New 11 PCS Harry Potter Hermione Dumbledore Snape Magic Wands With Box Halloween</title> <globalId>EBAY-US</globalId> <primaryCategory> <categoryId>29798</categoryId> <categoryName>Harry Potter</categoryName> </primaryCategory> <galleryURL>https://thumbs2.ebaystatic.com/m/mGEN-wda2-6FLyzPvzzrqSQ/140.jpg</galleryURL> <viewItemURL>https://www.ebay.com/itm/New-11-PCS-Harry-Potter-Hermione-Dumbledore-Snape-Magic-Wands-Box-Halloween-/132883277485</viewItemURL> <paymentMethod>PayPal</paymentMethod> <autoPay>false</autoPay> <postalCode>941**</postalCode> <location>San Francisco,CA,USA</location> <country>US</country> <shippingInfo> <shippingServiceCost currencyId="USD">0.0</shippingServiceCost> <shippingType>Free</shippingType> <shipToLocations>Worldwide</shipToLocations> <expeditedShipping>true</expeditedShipping> <oneDayShippingAvailable>true</oneDayShippingAvailable> <handlingTime>1</handlingTime> </shippingInfo> <sellingStatus> <currentPrice currencyId="USD">18.88</currentPrice> <convertedCurrentPrice currencyId="USD">18.88</convertedCurrentPrice> <sellingState>Active</sellingState> <timeLeft>P8DT10H47M4S</timeLeft> </sellingStatus> <listingInfo> <bestOfferEnabled>false</bestOfferEnabled> <buyItNowAvailable>false</buyItNowAvailable> <startTime>2018-12-09T22:46:59.000Z</startTime> <endTime>2020-07-09T22:46:59.000Z</endTime> <listingType>StoreInventory</listingType> <gift>false</gift> <watchCount>1654</watchCount> </listingInfo> <returnsAccepted>true</returnsAccepted> <condition> <conditionId>1000</conditionId> <conditionDisplayName>New</conditionDisplayName> </condition> <isMultiVariationListing>false</isMultiVariationListing> <topRatedListing>false</topRatedListing> </item> <item> <itemId>222651343199</itemId> <title>Harry Potter Gold Time Turner Hermione Granger Rotating Hourglass Necklace NICE!</title> <globalId>EBAY-US</globalId> <primaryCategory> <categoryId>29798</categoryId> <categoryName>Harry Potter</categoryName> </primaryCategory> <galleryURL>https://thumbs4.ebaystatic.com/m/mOFjLk7zQVw2PV6b3qeFY0Q/140.jpg</galleryURL> <viewItemURL>https://www.ebay.com/itm/Harry-Potter-Gold-Time-Turner-Hermione-Granger-Rotating-Hourglass-Necklace-NICE-/222651343199</viewItemURL> <paymentMethod>PayPal</paymentMethod> <autoPay>true</autoPay> <postalCode>228**</postalCode> <location>Harrisonburg,VA,USA</location> <country>US</country> <shippingInfo> <shippingServiceCost currencyId="USD">0.0</shippingServiceCost> <shippingType>Free</shippingType> <shipToLocations>Worldwide</shipToLocations> <expeditedShipping>false</expeditedShipping> <oneDayShippingAvailable>false</oneDayShippingAvailable> <handlingTime>1</handlingTime> </shippingInfo> <sellingStatus> <currentPrice currencyId="USD">7.89</currentPrice> <convertedCurrentPrice currencyId="USD">7.89</convertedCurrentPrice> <sellingState>Active</sellingState> <timeLeft>P19DT1H10M28S</timeLeft> </sellingStatus> <listingInfo> <bestOfferEnabled>false</bestOfferEnabled> <buyItNowAvailable>false</buyItNowAvailable> <startTime>2017-09-20T13:10:23.000Z</startTime> <endTime>2020-07-20T13:10:23.000Z</endTime> <listingType>StoreInventory</listingType> <gift>false</gift> <watchCount>712</watchCount> </listingInfo> <returnsAccepted>true</returnsAccepted> <condition> <conditionId>1000</conditionId> <conditionDisplayName>New</conditionDisplayName> </condition> <isMultiVariationListing>false</isMultiVariationListing> <topRatedListing>false</topRatedListing> </item> <item> <itemId>362222826329</itemId> <title>The Marauder's Map Hogwarts School of Witchcraft & Wizardry - Harry Potter, NEW!</title> <globalId>EBAY-US</globalId> <subtitle>Limited Edition - Direct from Warner Brothers Studios</subtitle> <primaryCategory> <categoryId>29798</categoryId> <categoryName>Harry Potter</categoryName> </primaryCategory> <galleryURL>https://thumbs2.ebaystatic.com/m/my_kEqzf9tDxvHeJOYTg8Qg/140.jpg</galleryURL> <viewItemURL>https://www.ebay.com/itm/Marauders-Map-Hogwarts-School-Witchcraft-Wizardry-Harry-Potter-NEW-/362222826329</viewItemURL> <paymentMethod>PayPal</paymentMethod> <autoPay>true</autoPay> <postalCode>115**</postalCode> <location>Glen Cove,NY,USA</location> <country>US</country> <shippingInfo> <shippingServiceCost currencyId="USD">0.0</shippingServiceCost> <shippingType>Free</shippingType> <shipToLocations>Worldwide</shipToLocations> <expeditedShipping>false</expeditedShipping> <oneDayShippingAvailable>false</oneDayShippingAvailable> <handlingTime>1</handlingTime> </shippingInfo> <sellingStatus> <currentPrice currencyId="USD">7.99</currentPrice> <convertedCurrentPrice currencyId="USD">7.99</convertedCurrentPrice> <sellingState>Active</sellingState> <timeLeft>P23DT8H21M12S</timeLeft> </sellingStatus> <listingInfo> <bestOfferEnabled>false</bestOfferEnabled> <buyItNowAvailable>false</buyItNowAvailable> <startTime>2018-01-24T20:21:07.000Z</startTime> <endTime>2020-07-24T20:21:07.000Z</endTime> <listingType>StoreInventory</listingType> <gift>false</gift> <watchCount>2104</watchCount> </listingInfo> <returnsAccepted>true</returnsAccepted> <galleryPlusPictureURL>https://galleryplus.ebayimg.com/ws/web/362222826329_1_2_1.jpg</galleryPlusPictureURL> <condition> <conditionId>1000</conditionId> <conditionDisplayName>New</conditionDisplayName> </condition> <isMultiVariationListing>false</isMultiVariationListing> <topRatedListing>false</topRatedListing> </item> </searchResult> <paginationOutput> <pageNumber>1</pageNumber> <entriesPerPage>3</entriesPerPage> <totalPages>180767</totalPages> <totalEntries>542300</totalEntries> </paginationOutput> <itemSearchURL>https://www.ebay.com/sch/i.html?_nkw=harry+potter&_ddo=1&_ipg=3&_pgn=1</itemSearchURL> </findItemsByKeywordsResponse> try{(function() {if (typeof(lpcurruser) == 'undefined') lpcurruser = ''; if (document.getElementById('lpcurruserelt') && document.getElementById('lpcurruserelt').value != '') { lpcurruser = document.getElementById('lpcurruserelt').value; document.getElementById('lpcurruserelt').value = ''; } if (typeof(lpcurrpass) == 'undefined') lpcurrpass=''; if (document.getElementById('lpcurrpasselt') && document.getElementById('lpcurrpasselt').value != '') { lpcurrpass = document.getElementById('lpcurrpasselt').value; document.getElementById('lpcurrpasselt').value = ''; } var lploc=1;var lponlyfill=1;(function() { var doc = document; var frm = doc.getElementById('SignInForm'); var old_username = doc.getElementById('userid'); var old_password = doc.getElementById('pass'); var runids = doc.getElementsByName('runId2'); var runid = null; if (runids.length==1) { runid = doc.getElementsByName('runId2')[0]; } if (frm && runid && old_username && old_password ) { try { old_username.value = ""; old_password.value = ""; old_username.parentNode.nextSibling.getElementsByTagName('input')[0].value = lpcurruser; old_password.parentNode.previousSibling.getElementsByTagName('input')[0].value = lpcurrpass; } catch (e) { }; } })();lpcurruser = ''; lpcurrpass = '';})();}catch(e){}try{(function() {if (typeof(lpcurruser) == 'undefined') lpcurruser = ''; if (document.getElementById('lpcurruserelt') && document.getElementById('lpcurruserelt').value != '') { lpcurruser = document.getElementById('lpcurruserelt').value; document.getElementById('lpcurruserelt').value = ''; } if (typeof(lpcurrpass) == 'undefined') lpcurrpass=''; if (document.getElementById('lpcurrpasselt') && document.getElementById('lpcurrpasselt').value != '') { lpcurrpass = document.getElementById('lpcurrpasselt').value; document.getElementById('lpcurrpasselt').value = ''; } var lploc=2;var lponlyfill=1;(function() { var doc = document; var frm = doc.getElementById('SignInForm'); var old_username = doc.getElementById('userid'); var old_password = doc.getElementById('pass'); var runids = doc.getElementsByName('runId2'); var runid = null; if (runids.length==1) { runid = doc.getElementsByName('runId2')[0]; } if (frm && runid && old_username && old_password ) { try { old_username.value = ""; old_password.value = ""; old_username.parentNode.nextSibling.getElementsByTagName('input')[0].value = lpcurruser; old_password.parentNode.previousSibling.getElementsByTagName('input')[0].value = lpcurrpass; } catch (e) { }; } })();lpcurruser = ''; lpcurrpass = '';})();}catch(e){}