I'm trying to pully xml data from ebay. I've used their tutorial. Basically just changed header and xml with mine. And it doesn't return any data. Just getting else statement for empty variable "Oops! Must not have gotten the response!"
<?php
$endpoint = 'http://ift.tt/Km6LJ3';
function constructPostCallAndGetResponse($endpoint)
{
// create the xml request that will be POSTed
$xml = '<?xml version="1.0" encoding="utf-8"?>';
$xml .= '<GetSellerListRequest xmlns="urn:ebay:apis:eBLBaseComponents">';
$xml .= '<RequesterCredentials>';
$xml .= '<eBayAuthToken>AgAAAA**AQAAAA**aAAAAA**hOj2VA**nY+sHZ2PrBmdj6wVnY+sEZ2PrA2dj6wHmYqnAZWGpAidj6x9nY+seQ**07sCAA**AAMAAA**oseV4XEgK8KU1ndWS1RdDGpSfkhIS8d5k3ZmMGzfV/ihVOrAlkCmQ6tIJamJHTEajKXAzOvwc7iL8K4pdFIfGkmQqrKjlUO4tKTKNJQerqF47q6cxJhh4lNMi06zznvB+UpjNyrPTGLJn2kXuZ+Fm1hzQck2ECcljDAdu2PsCFFYVXphQ7OsFPsY1dOFYQrh4abPYype0hKhMgSQT/X41EPeiMRw51cwNgijzwl5gGvnm9CNsz3ONbZBRBu3gvRJ0PiWjTI1s0VpYZvN87wKHuvrbifzNuY21qW9Dr/j5SpgkFcWoQ3vfW7uwC8vcBtVfrHFZPotQK0pQSmcjnfYyBA7S2/y1IQuJ6ApNp16EIa2ERUpJiwGLFtlw1uznykCLWWRTy7Htvd47D5P0CM21xWpFz4D1UYJJv4OuI7VahWAdSUn4uF5wtp+ULLpWhqoiGpN7wvtcEaoH1oCuDtwLMBlIx8i6H3ClY4RzWz2xjGx4yrOA5vBou3QCM5dIZyLXohXUUgP65iATs+j4DnC5OAvtjZNCTZ7s1PsTYT8LLuVCYAE1x5AXcHqJ3e7YFbwqzakXhPmu0Y9y/qeo/gMJApoTS7bjcYwvh3KXobMtlOg1U0xQm5CjWpo6aqHStO33NvXYhrs07Wp2uRdo8KJ/+8fL3D01u3mM8D7aH5vKNuRX/hC9zAlEeVbzdXwQ7GCI/BlGcA6UI3ZHmXeh6Z8ZtesF20dCzqCuUx+LgTRDgyqb+py517/QicRZlTj9qci</eBayAuthToken>';
$xml .= '</RequesterCredentials>';
$xml .= '<UserID>imda123</UserID>';
$xml .= '<StartTimeFrom>2015-01-04T21:59:59</StartTimeFrom> ';
$xml .= '<StartTimeTo>2015-02-20T21:59:59</StartTimeTo>';
$xml .= '<Pagination ComplexType="PaginationType">';
$xml .= '<EntriesPerPage>6</EntriesPerPage>';
$xml .= '<PageNumber>1</PageNumber>';
$xml .= '</Pagination>';
$xml .= '<DetailLevel>ReturnAll</DetailLevel>';
$xml .= '<OutputSelector>ItemArray.Item.SKU,ItemArray.Item.Title,ItemArray.Item.ItemID,ItemArray.Item.SellingStatus.CurrentPrice</OutputSelector>';
$xml .= '</GetSellerListRequest>';
$session = curl_init($endpoint); // create a curl session
curl_setopt($session, CURLOPT_POST, true); // POST request type
curl_setopt($session, CURLOPT_POSTFIELDS, $xml); // 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-COMPATIBILITY-LEVEL:907',
'X-EBAY-API-DEV-NAME:2469057b-9f4d-4425-9502-4909dac58abd',
'X-EBAY-API-APP-NAME:HarisMur-1b8a-4d28-9d36-3fe8ce8968fb',
'X-EBAY-API-CERT-NAME:3a3f4f3a-e17d-4ddd-bd55-167e7502bd21',
'X-EBAY-API-SITEID:0',
'X-EBAY-API-CALL-NAME:GetSellerList'
);
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
$resp = simplexml_load_string(constructPostCallAndGetResponse($endpoint));
// Check to see if the response was loaded, else print an error
if ($resp) {
$results = '';
// If the response was loaded, parse it and build links
foreach($resp->Item as $item) {
$link = $item->ViewItemURLForNaturalSearch;
$title = $item->Title;
// For each SearchResultItem node, build a link and append it to $results
$results .= "<a href=\"$link\">$title</a><br/>";
}
}
// If there was no response, print an error
else {
$results = "Oops! Must not have gotten the response!";
}
echo $results;
?>
No comments:
Post a Comment