ebay php api,使用XML和PHP解析eBay Trading API

我的身份验证工作正在进行,并且正在提供正确的数据,但是它引入了整个HTML文档,但只是作为代码,并没有正确渲染它。

最近的事情在这里我可以找到这个答案在这里:Ebay api GetSellerList, Parsing response XML

然而解决方案仍然不起作用。

解析eBay的XML,我认为我必须使用节点,但从未在&很混乱。尝试了一堆东西,我会继续尝试,直到我能得到这个工作。

感谢您的努力!

[小时]

这是我从这段代码中得到的回应的屏幕截图:

https://imgur.com/N1yeAnp

红线显示一系列信息,包括API调用的时间,失败/成功布尔& API版本(987)。

黄线显示​​HTML开始和放置的位置结束,并在页面的另一端。

另外我知道我的文档顶部有一个doctype和html。即使我从doctype中取出它到最后一个HTML硬编码部分“使用用户Tocken ID,我们可以将用户数据导入到我们的网站。”仍然不起作用,并提供相同的HTML硬编码。

链接到pastebin,如果它更容易阅读:http://pastebin.com/LYJHpLnK

Get eBay User Items (Result)

Testing eBay Connection Plugin

Receiving User Tocken

With a User Tocken ID we can import user data to our website.

//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 = 'FetchToken';

///Build the request Xml string

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

$requestXmlBody .= '';

$requestXmlBody .= ''.$_SESSION["eBaySession"].'';

$requestXmlBody .= '';

//Create a new eBay session with all details pulled in from included keys.php

$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('

Error sending request');

//Xml string is parsed and creates a DOM Document object

$responseDoc = new DomDocument();

$responseDoc->loadXML($responseXml);

//get any error nodes

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

//if there are error nodes

if($errors->length > 0)

{

echo '

eBay returned the following error(s):';

//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');

//Display code and shortmessage

echo '

', $code->item(0)->nodeValue, ' : ', str_replace(">", ">", str_replace("item(0)->nodeValue));

//if there is a long message (ie ErrorLevel=1), display it

echo '
User Session ID: '.$_COOKIE["eBaySession"].'';

if(count($longMsg) > 0)

echo '
', str_replace(">", ">", str_replace("item(0)->nodeValue));

}

else //no errors

{

//get the nodes needed

$eBayAuthTokenNode = $responseDoc->getElementsByTagName('eBayAuthToken');

//Display the details

//echo '
User Session ID: '.$_SESSION["eBaySession"].'';

//echo '
User Token: '.$eBayAuthTokenNode->item(0)->nodeValue.'';

$verb = 'GetSellerList';

$username = $_GET["username"];

$CreateTimeFrom = gmdate("Y-m-d\TH:i:s",time()); //current time

$CreateTimeTo = date('Y-m-d', strtotime("+3 months", strtotime($CreateTimeFrom)));

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

$requestXmlBody .= '';

$requestXmlBody .= ''.$username.'';

$requestXmlBody .= 'ReturnAll';

$requestXmlBody .= 'RFC 3066';

$requestXmlBody .= 'Low';

$requestXmlBody .= '987';

$requestXmlBody .= ''.$eBayAuthTokenNode->item(0)->nodeValue.'';

$requestXmlBody .= ''.$CreateTimeFrom.'';

$requestXmlBody .= ''.$CreateTimeTo.'';

$requestXmlBody .= ''.$CreateTimeFrom.'';

$requestXmlBody .= ''.$CreateTimeTo.'';

$requestXmlBody .= '200';

$requestXmlBody .= 'ItemArray.Item.Title';

$requestXmlBody .= 'ItemArray.Item.Description';

$requestXmlBody .= 'ItemArray.Item.BuyItNowPrice';

$requestXmlBody .= 'ItemArray.Item.Quantity';

$requestXmlBody .= '';

//Create a new eBay session with all details pulled in from included keys.php

$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('

Error sending request');

//Xml string is parsed and creates a DOM Document object

$responseDoc = new DomDocument();

$responseDoc->loadXML($responseXml);

$html = $responseDoc->saveHTML();

//echo $html;

echo $responseXml;

}

//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';

//Time with respect to GMT

//by default retreive orders in last 30 minutes

$CreateTimeFrom = gmdate("Y-m-d\TH:i:s",time()-1800); //current time minus 30 minutes

$CreateTimeTo = gmdate("Y-m-d\TH:i:s");

//If you want to hard code From and To timings, Follow the below format in "GMT".

//$CreateTimeFrom = YYYY-MM-DDTHH:MM:SS; //GMT

//$CreateTimeTo = YYYY-MM-DDTHH:MM:SS; //GMT

///Build the request Xml string

//by default retreive orders in last 30 minutes

$CreateTimeFrom = gmdate("Y-m-d\TH:i:s",time()-1800); //current time minus 30 minutes

$CreateTimeTo = gmdate("Y-m-d\TH:i:s");

//send the request and get response

$responseXml = $session->sendHttpRequest($requestXmlBody);

if(stristr($responseXml, 'HTTP 404') || $responseXml == '')

die('

Error sending request');

//Xml string is parsed and creates a DOM Document object

$responseDoc = new DomDocument();

$responseDoc->loadXML($responseXml);

$title_nodes = $responseDoc->getElementsByTagName('Title');

$titles = array();

foreach ($title_nodes as $node) {

$titles[] = $node->nodeValue;

}

?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值