question

sjjs1985 avatar image
1 Like"
sjjs1985 asked

How to get product info using GetSingleItem PHP

Hi.

How do I get the title, price, image and description of a product that I know the ID of and echo out in html?

 

I have found this code which works but obviously prints xml.

<?php

$appID = 'samsharp-5067-49a2-942d-2cdab859d2f5';

$exexex = $_GET["item"];

$request = '<?xml version="1.0" encoding="utf-8"?>

            <GetSingleItemRequest xmlns="urn:ebay:apis:eBLBaseComponents" >

            <ItemID>'.$exexex.'</ItemID>

            <IncludeSelector>Details,ShippingCosts,ItemSpecifics,Variations</IncludeSelector>

            </GetSingleItemRequest>';

 

$callName = 'GetSingleItem';

$compatibilityLevel = 647;

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

 

$headers[] = "X-EBAY-API-CALL-NAME: $callName";

$headers[] = "X-EBAY-API-APP-ID: $appID";

$headers[] = "X-EBAY-API-VERSION: $compatibilityLevel";

$headers[] = "X-EBAY-API-REQUEST-ENCODING: XML";

$headers[] = "X-EBAY-API-RESPONSE-ENCODING: XML";

$headers[] = "X-EBAY-API-SITE-ID: 0";

$headers[] = "Content-Type: text/xml";

 

$curl = curl_init($endpoint);

 

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);

curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($curl, CURLOPT_POST, 1);

curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

curl_setopt($curl, CURLOPT_POSTFIELDS, $request);

 

$response = curl_exec($curl);

header("Content-type: text/xml");

echo $response;

?>

 

Any help greatly appreciated.

 

Thanks

php-getsingleitem-id
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

helios825 avatar image
0 Likes"
helios825 answered

Sam:

 

You need to parse your XML first, then pluck out the strings/text you then want to embed within HTML output.

 

$data = simplexml_load_string($response) ;
$AckResponse = $data->Ack ;
echo($AckResponse) ;

 

That first line will load the data into an XML object that you can address directly (next line), or traverse via a foreach() loop if you had multiple items (well, not for GetSingleItem).

 

PHP.net Manual:  http://php.net/manual/en/function.simplexml-load-string.php

 

Also good practice to keep the Compat.Level fairly current, mask out your AppID in public, and be frugal with only the IncludeSelectors that you need.

 

-h

 

10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

sjjs1985 avatar image
0 Likes"
sjjs1985 answered

Thanks for your response. I'm pretty new to xml so all help greatly appreciated. I realised I included my appid after I had posted but couldn't edit it out.

 

Please could you just show me an example of how to get an item out of the array, so just return the item title for example. 

Also, when I run my code with yours I get an error:

 

This page contains the following errors:

error on line 66 at column 1: Extra content at the end of the document

Below is a rendering of the page up to the first error.

 

Many thanks

Sam

10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

telekommunikator avatar image
0 Likes"
telekommunikator answered

ebay get new refresh token?

· 1
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

???????????????????????
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.