PHP XML-XML curl function not working. Please help

This is a discussion on PHP XML-XML curl function not working. Please help within the PHP Language forums, part of the PHP Programming Forums category; Hi Everyone, I'm trying to get the following php script to work with an ebay API. It sends XML ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-11-2008
raj
 
Posts: n/a
Default PHP XML-XML curl function not working. Please help

Hi Everyone,

I'm trying to get the following php script to work with an ebay API. It
sends XML and then returns XML and formats it into links. THing is it
doesn;t work, and I'm not sure why. Can anyone see where I'm going
wrong?

Thank you in advance,

Raj

<?php

$query = 'ipod';

$endpoint = 'http://open.api.ebay.com/shopping?';

$resp =
simplexml_load_string(constructPostCallAndGetRespo nse($endpoint,
$query));

if ($resp) {
$results = '';

foreach($resp->Item as $item) {
$link = $item->ViewItemURLForNaturalSearch;
$title = $item->Title;

$results .= "<a href=\"$link\">$title</a><br/>";
}
}

else {
$results = "Oops! Must not have gotten the response!";
}
?>

<!-- Build the HTML page with values from the call response -->
<html>
<head>
<title>
eBay Search Results for <?php echo $query; ?>
</title>
</head>
<body>

<h1>eBay Search Results for <?php echo $query; ?></h1>

<?php echo $results;?>

</body>
</html>

<?php

function constructPostCallAndGetResponse($endpoint, $query)
{
$xmlRequest = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
$xmlRequest .= "<FindItemsAdvancedRequest
xmlns=\"urn:ebay:apis:eBLBaseComponents\">";
$xmlRequest .= "<QueryKeywords>";
$xmlRequest .= $query;
$xmlRequest .= "</QueryKeywords></FindItemsAdvancedRequest>";

$session = curl_init($endpoint); // create a
curl session

curl_setopt($session, CURLOPT_POST, true); // POST request type
curl_setopt($session, CURLOPT_POSTFIELDS, $xmlRequest); // set the
body of the POST
curl_setopt($session, CURLOPT_RETURNTRANSFER, true); // return
values as a string - not to std out
$headers = array(
'X-EBAY-API-CALL-NAME: FindItemsAdvanced',
'X-EBAY-API-SITEID: 0', // Site 0
is for US
'X-EBAY-API-APP-ID: My ID Goes Here. Removed for security',
'X-EBAY-API-VERSION: 559',
"X-EBAY-API-REQUEST-ENCODING: XML",
'Content-Type: text/xml;charset=utf-8',
);
curl_setopt($session, CURLOPT_HTTPHEADER, $headers); //set
headers using the above array of headers

$responseXML = curl_exec($session); // send the request
curl_close($session);

return $responseXML; // returns a string
} // function
?>

Reply With Quote
  #2 (permalink)  
Old 04-11-2008
Captain Paralytic
 
Posts: n/a
Default Re: PHP XML-XML curl function not working. Please help

On 11 Apr, 12:25, raj <r...@nospam.com> wrote:
> Hi Everyone,
>THing is it doesn;t work, and I'm not sure why.


Based on the statement "it doesn't work", I can tell you hat there is
something wrong.

If you would care to give us more information about precisely in what
way "it doesn't work", such as what actually happens when you try it,
we will try to give more refined suggestions.

Garbage in - garbage out.

Reply With Quote
  #3 (permalink)  
Old 04-11-2008
Álvaro G. Vicario
 
Posts: n/a
Default Re: PHP XML-XML curl function not working. Please help

raj escribió:
> I'm trying to get the following php script to work with an ebay API. It
> sends XML and then returns XML and formats it into links. THing is it
> doesn;t work, and I'm not sure why. Can anyone see where I'm going wrong?


When I run the code you paste, the eBay server replies:

Application ID invalid

> 'X-EBAY-API-APP-ID: My ID Goes Here. Removed for security',


Ah, yep, this must be the reason.

My guess is that you have some silly typo in your code but since your
XML parser routines cannot handle error responses you don't even see the
error message. Just try this to see raw XML:

echo constructPostCallAndGetResponse($endpoint, $query);

Next time try to change "does not work" with something more informative
like "I see no error messages but the response is empty".



--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:55 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0