使用ebay api获取所有详细信息

时间:2016-03-14 07:00:07

标签: php ebay ebay-api

我试图以xml格式使用ebay api获取所有项目。

请参阅以下代码。

require_once('config/ebay_config.php');
require_once('helpers/eBaySession.php');
session_start();
//SiteID must also be set in the Request's XML
//SiteID = 0  (US) - UK = 3, Canada = 2, Australia = 15, ....
//SiteID Indicates the eBay site to associate the call with
$siteID = 0;
//the call being made:
$verb = 'GetSellerList';
///Build the request Xml string
$requestXmlBody = '<?xml version="1.0" encoding="utf-8" ?>';
$requestXmlBody .= '<GetSellerListRequest xmlns="urn:ebay:apis:eBLBaseComponents">';
$requestXmlBody .= '<EndTimeFrom>2015-12-12T11:36:06.487Z</EndTimeFrom>';
$requestXmlBody .= '<EndTimeTo>2016-03-12T11:36:06.487Z</EndTimeTo>';
$requestXmlBody .= '<RequesterCredentials><eBayAuthToken>' . $userToken . '</eBayAuthToken></RequesterCredentials>';
$requestXmlBody .= '<UserID>****</UserID>';
$requestXmlBody .= '<DetailLevel>ItemReturnDescription</DetailLevel>';
$requestXmlBody .= '<Pagination><EntriesPerPage>200</EntriesPerPage><PageNumber>1</PageNumber></Pagination>';
$session = new eBaySession($userToken, $devID, $appID, $certID, $serverUrl, $compatabilityLevel, $siteID, $verb);

//send the request and get response
$responseXml = $session->sendHttpRequest($requestXmlBody);
if (stristr($responseXml, 'HTTP 404') || $responseXml == '')
    die('<P>Error sending request');


//Xml string is parsed and creates a DOM Document object
$responseDoc = new DomDocument();
$responseDoc->loadXML($responseXml);

$errors = $responseDoc->getElementsByTagName('Errors');

if ($errors->length > 0) {
    echo '<P><B>eBay returned the following error(s):</B>';
    //display each error
    //Get error code, ShortMesaage and LongMessage
    $code = $errors->item(0)->getElementsByTagName('ErrorCode');
    $shortMsg = $errors->item(0)->getElementsByTagName('ShortMessage');
    $longMsg = $errors->item(0)->getElementsByTagName('LongMessage');

    echo '<P>', $code->item(0)->nodeValue, ' : ', str_replace(">", "&gt;", str_replace("<", "&lt;", $shortMsg->item(0)->nodeValue));

    echo '<BR/>User Session ID: ' . $_COOKIE["eBaySession"] . '';
    if (count($longMsg) > 0)
        echo '<BR>', str_replace(">", "&gt;", str_replace("<", "&lt;", $longMsg->item(0)->nodeValue));
}

else { //no errors
    //get the nodes needed
    $sellerNode = $responseDoc->getElementsByTagName('Seller');

    if ($sellerNode->length > 0) {
        echo '<P><B>Seller</B>';
        $userIDNode = $sellerNode->item(0)->getElementsByTagName('UserID');
        $scoreNode = $sellerNode->item(0)->getElementsByTagName('FeedbackScore');
        $regDateNode = $sellerNode->item(0)->getElementsByTagName('RegistrationDate');

        echo '<BR>UserID: ', $userIDNode->item(0)->nodeValue;
        echo '<BR>Feedback Score: ', $scoreNode->item(0)->nodeValue;
        echo '<BR>Registration Date: ', $regDateNode->item(0)->nodeValue;
    }

}

它只返回卖家信息,但提供有关所有详细信息的所有项目的建议。

另外还有一件事,我已经完成了登录ebay api,并且还从url下面的ebay网站上获得了成功消息,但我想在用户ID上抛出一个特定的PHP页面。

https://signin.ebay.com/ws/eBayISAPI.dll?SignIn&RuName=<?php echo $RuName; ?>&SessID=<?php echo $sessionID; ?>

1 个答案:

答案 0 :(得分:1)

当你说'所有项目&#39;您的意思是要检索所有卖家列表:

您需要将初始请求中的DetailLevel节点更改为&#39; ReturnAll&#39;。有关详细信息,请参阅以下API页面。请注意,技术上不建议使用ReturnAll DetailLevel,因此您可能希望准确找到所需内容并仅返回该详细程度。

eBay GetSellerList

如果您正在查找某个类别中的所有项目(或与您的卖家帐户无关),如果我没记错的话,您需要使用查找API。我原来说的是广告,但那不是eBay = p