Php 易趣交易API additem调用不返回任何内容,获取';未定义变量:响应';加载页面时出错
我正在尝试使用Php 易趣交易API additem调用不返回任何内容,获取';未定义变量:响应';加载页面时出错,php,ebay-api,Php,Ebay Api,我正在尝试使用addItem调用添加列表。当前正在尝试使用从易趣收到的沙盒凭据 我使用本教程来完成以下操作: 我正确地接收了键值,并适当地设置了参数。加载页面时,会出现以下错误: Notice: Undefined variable: response in F:\wamp\www\ebay\test1\addItem.php on line 180 当我点击addItem按钮时,它不会显示任何错误,但也不会显示成功消息。任何帮助都是值得感激的 整个代码如下所示: 和沙盒键值。因为respos
addItem
调用添加列表。当前正在尝试使用从易趣收到的沙盒凭据
我使用本教程来完成以下操作:
我正确地接收了键值,并适当地设置了参数。加载页面时,会出现以下错误:
Notice: Undefined variable: response in F:\wamp\www\ebay\test1\addItem.php on line 180
当我点击addItem
按钮时,它不会显示任何错误,但也不会显示成功消息。任何帮助都是值得感激的
整个代码如下所示:
和沙盒键值。因为respose变量在此块中
if (!empty($_POST)) {
// grab our posted keywords and call helper function
// TODO: check if need urlencode
$title = $_POST['title'];
$categoryID = $_POST['categoryID'];
$startPrice = $_POST['startPrice'];
$pictureURL = $_POST['pictureURL'];
$description = $_POST['description'];
// call the getAddItem function to make AddItem call
$response = getAddItem($title, $categoryID, $startPrice, $pictureURL, $description);
}
重新加载页面时未设置$response变量,因为它与$\u POST块一起使用。因此,仅在单击“添加项目”按钮时设置 请在给定条件内复制整个响应块。即: 如果(isset($response)){ //本节中的整个响应块 } 因此,新的响应块代码将为:
// Display information to user based on AddItem response.
if(isset($response)){
// Convert the xml response string in an xml object
$xmlResponse = simplexml_load_string($response);
// Verify that the xml response object was created
if ($xmlResponse) {
// Check for call success
if ($xmlResponse->Ack == "Success") {
// Display the item id number added
echo "<p>Successfully added item as item #" . $xmlResponse->ItemID . "<br/>";
// Calculate fees for listing
// loop through each Fee block in the Fees child node
$totalFees = 0;
$fees = $xmlResponse->Fees;
foreach ($fees->Fee as $fee) {
$totalFees += $fee->Fee;
}
echo "Total Fees for this listing: " . $totalFees . ".</p>";
} else {
// Unsuccessful call, display error(s)
echo "<p>The AddItem called failed due to the following error(s):<br/>";
foreach ($xmlResponse->Errors as $error) {
$errCode = $error->ErrorCode;
$errLongMsg = htmlentities($error->LongMessage);
$errSeverity = $error->SeverityCode;
echo $errSeverity . ": [" . $errCode . "] " . $errLongMsg . "<br/>";
}
echo "</p>";
}
}
}
//根据AddItem响应向用户显示信息。
如果(isset($response)){
//转换xml对象中的xml响应字符串
$xmlResponse=simplexml\u load\u字符串($response);
//验证是否已创建xml响应对象
如果($xmlResponse){
//检查呼叫是否成功
如果($xmlResponse->Ack==“成功”){
//显示添加的项目id号
echo“已成功地将项添加为项#”。$xmlResponse->ItemID。“
”;
//计算上市费用
//循环遍历“费用”子节点中的每个费用块
$totalFees=0;
$fees=$xmlResponse->fees;
foreach($fees->费用为$Fee){
$totalFees+=$fee->fee;
}
echo“此列表的总费用:.$totalFees.”;
}否则{
//呼叫失败,显示错误
echo“调用的附加项由于以下错误而失败:
”;
foreach($xmlResponse->Errors as$error){
$errCode=$error->ErrorCode;
$errLongMsg=htmlentities($error->LongMessage);
$errSeverity=$error->SeverityCode;
echo$errSeverity.:[“$errCode.”]“$errLongMsg.”
”;
}
回声“”;
}
}
}
if (!empty($_POST)) {
// grab our posted keywords and call helper function
// TODO: check if need urlencode
$title = $_POST['title'];
$categoryID = $_POST['categoryID'];
$startPrice = $_POST['startPrice'];
$pictureURL = $_POST['pictureURL'];
$description = $_POST['description'];
// call the getAddItem function to make AddItem call
$response = getAddItem($title, $categoryID, $startPrice, $pictureURL, $description);
}
// Display information to user based on AddItem response.
if(isset($response)){
// Convert the xml response string in an xml object
$xmlResponse = simplexml_load_string($response);
// Verify that the xml response object was created
if ($xmlResponse) {
// Check for call success
if ($xmlResponse->Ack == "Success") {
// Display the item id number added
echo "<p>Successfully added item as item #" . $xmlResponse->ItemID . "<br/>";
// Calculate fees for listing
// loop through each Fee block in the Fees child node
$totalFees = 0;
$fees = $xmlResponse->Fees;
foreach ($fees->Fee as $fee) {
$totalFees += $fee->Fee;
}
echo "Total Fees for this listing: " . $totalFees . ".</p>";
} else {
// Unsuccessful call, display error(s)
echo "<p>The AddItem called failed due to the following error(s):<br/>";
foreach ($xmlResponse->Errors as $error) {
$errCode = $error->ErrorCode;
$errLongMsg = htmlentities($error->LongMessage);
$errSeverity = $error->SeverityCode;
echo $errSeverity . ": [" . $errCode . "] " . $errLongMsg . "<br/>";
}
echo "</p>";
}
}
}