2016-02-29 68 views
2

我在使用eBay API時遇到問題,我正嘗試將我的庫存上傳到我的eBay商店。我已經註冊爲開發人員並閱讀了教程和示例,但出於某種原因,這不會起作用,下面是我通過數據庫生成的當前XML。Ebay Api - 使用php添加產品

<?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>[email protected]</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. 

我的頭和捲曲

$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複製到我的文件並嘗試運行該程序,然後我收到錯誤消息回來?

+0

你爲什麼不使用https://github.com/davidtsadler/ebay-sdk-php做?我會推薦它。 –

回答

1

UPDATE

說明標籤內的HTML標籤打破了XML。對於要使用CDATA附上你的描述一種解決方法:

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

詳情:

  • Error: [21843] The job context object is not supported by Action Service Framework.似乎是由頭部和XML之間的不匹配挑釁。

看到這裏的細節:https://stackoverflow.com/a/13791811/2797243

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

可以有很多原因,你都recieiving這個錯誤,但我們將只關注2種情況:

  1. 您可能會收到此錯誤,因爲請求xml文檔中給定的根元素沒有匹配eBay架構中的任何元素聲明。

回答名稱:錯誤20170 - 架構XML請求錯誤 回答鏈接:https://ebaydts.com/eBayKBDetails?KBid=897

  • 另一個常見原因是您的具有HTML或XML保留字符。對於需要使用CDATA附上描述的解決方法。
  • +0

    eBayAuthToken位於XML的底部。 – nats0128

    +1

    @ nats0128 ups,對不起。我編輯答案。 –

    +1

    @ nats0128 descr中的html是問題所在。 –

    0

    嘗試改變:

    <AddItems xmlns="urn:ebay:apis:eBLBaseComponents">

    <AddItemsRequest xmlns="urn:ebay:apis:eBLBaseComponents">

    和:

    </AddItems>

    </AddItemsRequest>

    +0

    同樣的錯誤,改變了你所說的,甚至把頭文件中的Additem改成了AddItemsRequest,並且帶回了錯誤:[2] API調用「AddItemsRequest」在此版本中無效或不受支持。 @Isaac – nats0128