Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplay XML as response in PHP with eBay API
    text
    copied!<p>Following <a href="http://developer.ebay.com/DevZone/finding/HowTo/GettingStarted_PHP_XML_XML/GettingStarted_PHP_XML_XML.html#step3" rel="nofollow">tutorial</a> shows how to display data as HTML based on that I just need to show response of XML as opposed to parsing it. I have tried to find solution but didn't have any luck. Any help will be appreciated.</p> <pre><code>&lt;?php $endpoint = 'http://svcs.ebay.com/services/search/FindingService/v1'; // URL to call $query = 'iphone'; // Supply your own query keywords as needed // Construct the findItemsByKeywords POST call // Load the call and capture the response returned by the eBay API // The constructCallAndGetResponse function is defined below $resp = simplexml_load_string(constructPostCallAndGetResponse($endpoint, $query)); // Check to see if the call was successful, else print an error if ($resp-&gt;ack == "Success") { $results = ''; // Initialize the $results variable // Parse the desired information from the response foreach($resp-&gt;searchResult-&gt;item as $item) { $link = $item-&gt;viewItemURL; $title = $item-&gt;title; // Build the desired HTML code for each searchResult.item node and append it to $results $results .= "&lt;tr&gt;&lt;td&gt;&lt;img src=\"$pic\"&gt;&lt;/td&gt;&lt;td&gt;&lt;a href=\"$link\"&gt;$title&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;"; } } else { // If the response does not indicate 'Success,' print an error $results = "&lt;h3&gt;Oops! The request was not successful"; $results .= "AppID for the Production environment.&lt;/h3&gt;"; } function constructPostCallAndGetResponse($endpoint, $query) { global $xmlrequest; // Create the XML request to be POSTed $xmlrequest = "&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n"; $xmlrequest .= "&lt;findItemsByKeywordsRequest xmlns=\"http://www.ebay.com/marketplace/search/v1/services\"&gt;\n"; $xmlrequest .= "&lt;keywords&gt;"; $xmlrequest .= $query; $xmlrequest .= "&lt;/keywords&gt;\n"; $xmlrequest .= "&lt;paginationInput&gt;\n &lt;entriesPerPage&gt;3&lt;/entriesPerPage&gt;\n&lt;/paginationInput&gt;\n"; $xmlrequest .= "&lt;/findItemsByKeywordsRequest&gt;"; // Set up the HTTP headers $headers = array( 'X-EBAY-SOA-OPERATION-NAME: findItemsByKeywords', 'X-EBAY-SOA-SERVICE-VERSION: 1.3.0', 'X-EBAY-SOA-REQUEST-DATA-FORMAT: XML', 'X-EBAY-SOA-GLOBAL-ID: EBAY-GB', 'X-EBAY-SOA-SECURITY-APPNAME: ******', 'Content-Type: text/xml;charset=utf-8', ); $session = curl_init($endpoint); // create a curl session curl_setopt($session, CURLOPT_POST, true); // POST request type curl_setopt($session, CURLOPT_HTTPHEADER, $headers); // set headers using $headers array curl_setopt($session, CURLOPT_POSTFIELDS, $xmlrequest); // set the body of the POST curl_setopt($session, CURLOPT_RETURNTRANSFER, true); // $responsexml = curl_exec($session); // send the request curl_close($session); // close the session return $responsexml; // returns a string } // End of constructPostCallAndGetResponse function ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload