Ebay API integration in PHP
It's Ebay API Integreation of OLD Versions API. here we have added complete code with Blog, please download the file and check the code.
File Structure
-
- ebay-API-PHP
- API.css
- demo.php
- GettingStarted_PHP_NV_XML.html
- GettingStarted_PHP_NV_XML.jpg
- index.php
- ss-print.css
- ss-styles.css
- task.css
Index.php Code to understand the logic
/* All Variables for config values*/
$endpoint = 'http://svcs.ebay.com/services/search/FindingService/v1';
$version = '1.0.0';
$appid = 'raghusin-xxxxxxx-PRD-xxxxxxxxx-6ad6655b'; // Replace with your own AppID
$globalid = 'EBAY-US'; // Global ID of the eBay site you want to search (e.g., EBAY-DE)
$query = "ebay"; // You may want to supply your own query
$pgn='Pagination.PageNumber';
$safequery = urlencode($query); // Make the query URL-friendly
$i = '0'; // Initialize the item filter index to 0
/* Name of the data you want to search in array() format*/
$filterarray =array(
array(
'name' => 'MaxPrice',
'value' => '25',
'paramName' => 'Currency',
'paramValue' => 'USD'
),
array(
'name' => 'FreeShippingOnly',
'value' => 'true',
'paramName' => '',
'paramValue' => ''
),
array(
'name' => 'ListingType',
'value' => array('AuctionWithBIN','FixedPrice','StoreInventory'),
'paramName' => '',
'paramValue' => ''
),
);
// Generates an indexed URL snippet from the array of item filters
function buildURLArray ($filterarray) {
global $urlfilter;
global $i;
// Iterate through each filter in the array
foreach($filterarray as $itemfilter) {
foreach ($itemfilter as $key =>$value) {
if(is_array($value))
foreach($value as $j => $content)
$urlfilter .= "&itemFilter($i).$key($j)=$content";
else
if($value != "")
$urlfilter .= "&itemFilter($i).$key=$value";
}
$i++;
}
return "$urlfilter";
}
$start = time();
buildURLArray($filterarray); // Build the indexed item filter URL snippet
if (isset($_GET["xx"]))
$xx=$_GET["xx"];
else
$xx= '2';
/* Construct the findItemsByKeywords HTTP GET call */
echo "";
$apicall = "$endpoint?";
$apicall .= "OPERATION-NAME=findItemsByKeywords";
$apicall .= "&SERVICE-VERSION=$version";
$apicall .= "&SECURITY-APPNAME=$appid";
$apicall .= "&GLOBAL-ID=$globalid";
$apicall .= "&keywords=$safequery";
$apicall .= "&paginationInput.entriesPerPage=5";
$apicall .= "&paginationInput.pageNumber=".$xx;
$apicall .= "$urlfilter";
$resp = simplexml_load_file($apicall); // Load the call and capture the document returned by eBay API
// Check to see if the request was successful, else print an error
if ($resp->ack == "Success") {
$results = '';
foreach($resp->searchResult->item as $item) {
$end = time();
$pic = $item->galleryURL;
$link = $item->viewItemURL;
$title = $item->title;
$subtitle = $item->subtitle;
$paymentMethod = $item->paymentMethod;
if ($paymentMethod == 'PayPal')
$paymentMethod = "<img src='i/paypal.png'>";
foreach ($resp->searchResult->item->sellingStatus as $value)
$price = $item->sellingStatus->currentPrice;
foreach ($resp->paginationOutput as $value) {
$Pageno = $resp->paginationOutput->pageNumber;
$totalEntries = $resp->paginationOutput->totalEntries;
$totalPage = $resp->paginationOutput->totalPages;
}
$results .= "<div class='col-md-12' style='border-left:4px solid black; border-bottom: 1px solid #bcc; margin-top:2%;'><div class='col-md-3'><center><img src=\"$pic\" style='max-width: 100%;margin:1%;'></center></div><div class='col-md-9' ><h2> <a href='$link\' target='blank'>$title</a></h2><h5> $subtitle </h5> <h3>Price $$price </h3><p align='right'>$paymentMethod</p></div></div>";
}
} else {
$results = "<h3>Oops! The request was not successful. Make sure you are using a valid ";
$results .= "AppID for the Production environment.</h3>";
}
Click here to Download the sourcse code