我正在开发一些PHP来使用cURL的eBay API,我试过这个:
<?php
$dev_id = "sandboxDevId"; //Changed for security reasons
$app_id = "sandboxAppId"; //Changed for security reasons
$cert_id = "sandboxCertId"; //Changed for security reasons
$site_id = "186"; //spain
$xmlVersion = "1.0";
$encoding = "utf-8";
$api_endpoint = "https://api.sandbox.ebay.com/ws/api.dll";
$auth_token = "theAuthToken"; //The Auth token (Long String) for the seller user.
//I have changed it for the real token
$itemid = "110178474743"; //The item id in sandbox
$new_description = "Updating my item description with cURL";
$new_description = urldecode($new_description);
$stringXML = "<?xml version=\"".$xmlVersion."\" encoding=\"".$encoding."\"?>";
$stringXML .="<ReviseItemRequest xmlns=\"urn:ebay:apis:eBLBaseComponents\">";
$stringXML .="<ErrorLanguage>en_US</ErrorLanguage><Item><ItemID>".$itemid."</ItemID>";
$stringXML .="<Description>".$new_description."</Description>";
$stringXML .="</Item><RequesterCredentials>";
$stringXML .="<eBayAuthToken>".$auth_token."</eBayAuthToken></RequesterCredentials>";
$stringXML .="<WarningLevel>High</WarningLevel></ReviseItemRequest>";
$feed = new SimpleXMLElement($stringXML);
$headers = array
(
'X-EBAY-API-COMPATIBILITY-LEVEL: 963',
'X-EBAY-API-DEV-NAME: ' . $dev_id,
'X-EBAY-API-APP-NAME: ' . $app_id,
'X-EBAY-API-CERT-NAME: '. $cert_id,
'X-EBAY-API-CALL-NAME: ReviseItem',
'X-EBAY-API-SITEID: ' . $site_id,
);
$connection = curl_init();
curl_setopt($connection, CURLOPT_URL, $api_endpoint);
curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($connection, CURLOPT_HTTPHEADER, $headers);
curl_setopt($connection, CURLOPT_POST, 1);
curl_setopt($connection, CURLOPT_POSTFIELDS, $feed);
curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($connection);
curl_close($connection);
echo $response;
?>
我试图通过开发人员工具更改项目描述并且它有效,并且我已将XML打印为纯文本并且它似乎是正确的,但由于某种原因我收到以下错误:
2016-05-26 08:38:32 100121SeriousError00RequestError 51SeriousError00RequestError
它给我带来了两个错误,我已经在API参考上检查了它们:
#5 Serious error: XML Parse error.
和
#10012 Serious error: Invalid value for header "replaceable_value".
我无法弄清楚如何解决这些问题。
如果有人可以对这个问题有所了解,那将会有所帮助;这是我第一次使用cURL和XML,每一个帮助都会被贬低。
答案 0 :(得分:0)
#10012 Serious error: Invalid value for header "replaceable_value".
我只需要在本地检查元素(浏览器上的F12),它说错误来自API详细信息级别。
我在标题中添加了以下配置行:
X-EBAY-API-DETAIL-LEVEL: 0;
并且错误#10012似乎已经解决了。
出现错误#5是因为我以错误的方式将XML发送到eBay服务器。我只需将字符串作为参数传递给cURL:
curl_setopt($connection, CURLOPT_POSTFIELDS, $stringXML);
而不是尝试将其解析为XML对象。