php - Ebay Api - 使用 php 添加产品

标签 php web-applications ebay-api

我在使用 eBay API 时遇到问题,我正在尝试将我的库存上传到我的 eBay 商店。我已经注册为开发人员并通读了教程和示例,但由于某种原因这行不通,这是我当前通过数据库生成的 XML。

<?xml version="1.0" encoding="utf-8"?>
<AddItems xmlns="urn:ebay:apis:eBLBaseComponents">
<ErrorLanguage>en_US</ErrorLanguage>
<WarningLevel>High</WarningLevel>
<Item>
<Title>Fun Novelty Routemaster Red Bus Mug</Title>
<Description><p>Fun Novelty Routemaster Red Bus Mug</p><p>If you are looking for a novelty gift thats practical and looks great, then check out our funky kitchen and ceramics range.</p><p>The range is made from dolomite ceramics and finished in a high gloss glaze. Each comes in a decorative gift box to complete the look, plus if its a kitchen item then dolomite is food and microwave safe but cannot be put in the dishwasher.</p></Description>
<PrimaryCategory><CategoryID>14899</CategoryID>
</PrimaryCategory>
<StartPrice>9.99</StartPrice>
<CategoryMappingAllowed>true</CategoryMappingAllowed>
<ConditionID>1000</ConditionID>
<Country>GB</Country>
<Currency>GBP</Currency>
<DispatchTimeMax>3</DispatchTimeMax>
<ListingDuration>Days_30</ListingDuration>
<ListingType>FixedPriceItem</ListingType>
<PaymentMethods>PayPal</PaymentMethods>
<PayPalEmailAddress>info@3cheekymonkeys.co.uk</PayPalEmailAddress>
<PictureDetails><GalleryType>Gallery</GalleryType>
</PictureDetails>
<PostalCode>95125</PostalCode>
<ProductListingDetails><UPC>5055071655654</UPC>
<IncludeStockPhotoURL>true</IncludeStockPhotoURL>
<IncludePrefilledItemInformation>true</IncludePrefilledItemInformation>
<UseFirstProduct>true</UseFirstProduct>
<UseStockPhotoURLAsGallery>true</UseStockPhotoURLAsGallery>
<ReturnSearchResultOnDuplicates>true</ReturnSearchResultOnDuplicates>
</ProductListingDetails>
<Quantity>6</Quantity>
<ReturnPolicy><ReturnsAcceptedOption>ReturnsAccepted</ReturnsAcceptedOption>
<RefundOption>MoneyBack</RefundOption>
<ReturnsWithinOption>Days_14</ReturnsWithinOption>
<Description>If you are not satisfied, return the item for refund.    </Description>
<ShippingCostPaidByOption>Buyer</ShippingCostPaidByOption>
</ReturnPolicy>
<ShippingDetails><ShippingType>Flat</ShippingType>
<ShippingServiceOptions><ShippingServicePriority>1</ShippingServicePriority>
<ShippingService>UK_RoyalMailFirstClassStandard</ShippingService>
<FreeShipping>true</FreeShipping>
<ShippingServiceAdditionalCost>0.00</ShippingServiceAdditionalCost>
</ShippingServiceOptions>
</ShippingDetails>
<Site>UK</Site>
</Item>
<RequesterCredentials>
<eBayAuthToken>AUTHC CODE</eBayAuthToken>
</RequesterCredentials>
<WarningLevel>High</WarningLevel>
</AddItems>

这是来自 ebay 的结果

The AddItem called failed due to the following error(s):
Error: [21843] The job context object is not supported by Action Service Framework. 

我的标题和 CURL

    $headers = array(
    'X-EBAY-API-SITEID:'.SITEID,
    'X-EBAY-API-CALL-NAME:AddItem',
    'X-EBAY-API-REQUEST-ENCODING:'.RESPONSE_ENCODING,
    'X-EBAY-API-COMPATIBILITY-LEVEL:' . API_COMPATIBILITY_LEVEL,
    'X-EBAY-API-DEV-NAME:' . API_DEV_NAME,
    'X-EBAY-API-APP-NAME:' . API_APP_NAME,
    'X-EBAY-API-CERT-NAME:' . API_CERT_NAME,
    'Content-Type: text/xml;charset=utf-8'
);

// initialize our curl session
$session  = curl_init(API_URL);

// set our curl options with the XML request
curl_setopt($session, CURLOPT_HTTPHEADER, $headers);
curl_setopt($session, CURLOPT_POST, true);
curl_setopt($session, CURLOPT_POSTFIELDS, $xmlRequest);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);

// execute the curl request
$responseXML = curl_exec($session);

// close the curl session
curl_close($session);

// return the response XML
return $responseXML;

当从 AddItem 更改为 AddFixedPriceItemRequest 时,错误更改为

 Schema XML request error: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize..

当在 API 测试工具中运行示例时,它不会产生相同的结果,并且当使用提供的示例代码运行测试工具时,它一直有效,直到我将该示例 XML 复制到我的文件中并尝试运行该程序,然后我得到返回错误消息?

最佳答案

更新

描述标签中的 html 标签破坏了 xml。对于您想使用 CDATA 附上您的描述的解决方法:

<Description><![CDATA[ <p>Fun Novelty .. put in the dishwasher.</p>]]></Description>

详细信息:

  • 错误:[21843] 操作服务框架不支持作业上下文对象。 似乎是由 header 和 xml 之间的不匹配引起的。

详情请看这里:https://stackoverflow.com/a/13791811/2797243

  • Schema XML 请求错误:SimpleDeserializer 在它试图反序列化的内容中遇到了一个不符合预期的子元素。

您收到此错误的原因可能有很多,但我们只关注两种情况:

  1. 您可能会收到此错误,因为您的请求 xml 文档中给定的根元素与 eBay 架构中的任何元素声明都不匹配。

答案标题:错误 20170 - Schema XML 请求错误 回答链接:https://ebaydts.com/eBayKBDetails?KBid=897

  1. 另一个常见原因是您有 HTML 或 XML 保留字符。对于您想要使用 CDATA 附上您的描述的解决方法。

关于php - Ebay Api - 使用 php 添加产品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35708117/

相关文章:

php - 如何让 Laravel 5.4 与 AWS SQS 队列一起使用

java - Tomcat 不扫描 JAR 中的 JAR

java - android 互联网连接错误失败

oauth - eBay oauth token 和刷新 token

php - 有没有办法在 PHP 中跟踪垃圾收集器事件?

javascript - 动态更改页面(ajax)

php - Paypal 付款高级 : what is the return data for Direct Payment

.net - 所有项目的 VB.Net 和命名空间

c# - 易趣 API : How do I specify "Standard Shipping (FedEx Ground or FedEx Home Delivery®)" as a shipping service?

java - 无法使用 Apache Commons CSV 读取 CSV 文件 - IllegalArgumentException