0

update 2015-08-09:
I updated the question title to reflect more accuretly what I was asking
Original question title:
"loading ebay completed api into simplexml_load_string() but i am coming up empty"
I have also managed to find a solution answer given below.


At the moment I am trying to parse xml data from ebays Completed listing api.
It's a little tricky at the moment because the url I put into a browser returns xml.
However when I Use simplexml_load_string and have var_dump to see what it has I get: bool(false)
Can someone help me uncover where I went wrong or if this question has already been asked, please point me there

I have used $obj = simplexml_load_file () and recieved an error

simplexml_load_file(): I/O warning : failed to load external entity ""

I have also used $obj = new SimpleXMLElement() and the error i recived:

PHP Fatal error:  Uncaught exception 'Exception' with message 'String could not be parsed as XML'

My code is as follows:

index.php

 $appleid= appID;

function CompletedItems($search, $categoryId)
{
    global $appid;
    $url ="http://svcs.ebay.com/services/search/FindingService/v1?OPERATION-NAME=findCompletedItems&SERVICE-VERSION=1.7.0&SECURITY-APPNAME=".$appid."&GLOBAL-ID=EBAY-GB&RESPONSE-DATA-FORMAT=XML&REST-PAYLOAD&keywords=".$search."&CategoryID=".$categoryId."&itemFilter(0).name=SoldItemsOnly&itemFilter(0).value=true&sortOrder=PricePlusShippingLowest&paginationInput.entriesPerPage=1";
    $safeurl= urlencode($url);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $safeurl);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: text/xml'));
    $content = curl_exec($ch);
    $error   = curl_error($ch);
    curl_close($ch);

    $obj =  simplexml_load_string($content);

    echo"<h3>Completed Items</h3>";
    echo "Url: ".$url."<br>";
    var_dump($obj);

    return true;
}

I call the function with: CompletedItems("iPod Touch 4th Generation White (8 GB)", "73839");

the responce I get when I Load the page:

Url: http://svcs.ebay.com/services/search/FindingService/v1?OPERATION-NAME=findCompletedItems&SERVICE-VERSION=1.7.0&SECURITY-APPNAME=AppID&GLOBAL-ID=EBAY-GB&RESPONSE-DATA-FORMAT=XML&REST-PAYLOAD&keywords=Apple iPod Touch 4th Generation White (8 GB)&CategoryID=73839&itemFilter(0).name=SoldItemsOnly&itemFilter(0).value=true&sortOrder=PricePlusShippingLowest&paginationInput.entriesPerPage=1
bool(false)

However when I paste the link into a browser I receive this:

<findCompletedItemsResponse>
<ack>Success</ack><version>1.13.0</version><timestamp>2015-08-08T17:25:42.574Z</timestamp>
<searchResult count="1">
<item>
<itemId>191618220158</itemId>
<title>Apple iPod Touch 4th Generation White (8 GB)   FAULTY SPARES </title>
<globalId>EBAY-GB</globalId>
<primaryCategory>
<categoryId>73839</categoryId>
<categoryName>iPods & MP3 Players</categoryName>
</primaryCategory>
<galleryURL>http://thumbs3.ebaystatic.com/m/m-18kzi7sjy70452dp8PQQw/140.jpg</galleryURL>
<viewItemURL>http://www.ebay.co.uk/itm/Apple-iPod-Touch-4th-Generation-White-8-GB-FAULTY-SPARES-/191618220158?pt=LH_DefaultDomain_3</viewItemURL>
<productId type="ReferenceID">110859287</productId>
<paymentMethod>PayPal</paymentMethod><autoPay>false</autoPay>
<location>United Kingdom</location>
<country>GB</country>
<shippingInfo>
<shippingServiceCost currencyId="GBP">1.99</shippingServiceCost>
<shippingType>Flat</shippingType>
<shipToLocations>AU</shipToLocations>
<shipToLocations>Americas</shipToLocations>
<shipToLocations>Europe</shipToLocations>
<shipToLocations>Asia</shipToLocations>
</shippingInfo><sellingStatus>
<currentPrice currencyId="GBP">3.33</currentPrice>
<convertedCurrentPrice currencyId="GBP">3.33</convertedCurrentPrice>
<bidCount>3</bidCount><sellingState>EndedWithSales</sellingState>
</sellingStatus><listingInfo>
<bestOfferEnabled>false</bestOfferEnabled>
<buyItNowAvailable>false</buyItNowAvailable>
<startTime>2015-07-01T12:47:07.000Z</startTime>
<endTime>2015-07-08T12:47:07.000Z</endTime>
<listingType>Auction</listingType>
<gift>false</gift>
</listingInfo>
<condition>
<conditionId>7000</conditionId>
<conditionDisplayName>For parts or not working</conditionDisplayName>
</condition>
<isMultiVariationListing>false</isMultiVariationListing>
<topRatedListing>true</topRatedListing>
</item>
</searchResult>
<paginationOutput>
<pageNumber>1</pageNumber>
<entriesPerPage>1</entriesPerPage>
<totalPages>517</totalPages>
<totalEntries>517</totalEntries>
</paginationOutput>
</findCompletedItemsResponse>
ben jay hutton
  • 394
  • 3
  • 15
  • 1
    Please take a look here: [How do I get PHP Errors to display?](http://stackoverflow.com/q/1053424/367456) - `bool(false)` means there was an error loading the string as XML. Learn more here: [Dealing with XML errors (PHP Manual)](https://secure.php.net/manual/en/simplexml.examples-errors.php) and [simplexml error handling php](http://stackoverflow.com/a/8501780/367456). – hakre Aug 08 '15 at 21:07
  • thanks a lot Now I can find out where Im going wrong :) – ben jay hutton Aug 08 '15 at 21:12

1 Answers1

1

I rewrote my code so ultimatly it looks like this:

$appleid= appID;

function CompletedItems($search, $categoryId)
{
    echo"<h3>Completed Items</h3>";

    global $appid;
    $url = utf8_encode('http://svcs.ebay.com/services/search/FindingService/v1?OPERATION-NAME=findCompletedItems&SERVICE-VERSION=1.7.0&SECURITY-APPNAME='.$appid.'&GLOBAL-ID=EBAY-GB&RESPONSE-DATA-FORMAT=XML&REST-PAYLOAD&keywords='.$search.'&CategoryID=".$categoryId."&itemFilter(0).name=SoldItemsOnly&itemFilter(0).value=true&sortOrder=PricePlusShippingLowest&paginationInput.entriesPerPage=2');
    $xml = simplexml_load_file($url);
    echo $url."<br>";

    if ($xml === false) 
        {
            echo "Failed loading XML: ";
            foreach(libxml_get_errors() as $error) 
                {
                    echo "<br>", $error->message;
                }
        } 
        else 
        {
            echo"<img class='wrap' src='".$xml->searchResult->item->galleryURL."'  alt='ebay image' >";
            echo "Item Id: ".$xml->searchResult->item->itemId."<br>";
            echo "Title: ".$xml->searchResult->item->title."<br>";
            echo "Global Id: ".$xml->searchResult->item->globalId."<br>";
            echo "Primary Catergory: ".$xml->searchResult->item->primaryCategory->categoryId.", ".$xml->searchResult->item->primaryCategory->categoryName ."<br>";
            // More Code can go here
        }

    echo"<br><br><br><br>";

    return true;
}
ben jay hutton
  • 394
  • 3
  • 15