eBay API不返回XML格式

时间:2013-04-23 21:39:48

标签: php api ebay

我正在尝试调用eBay API并以XML格式返回结果(我正在使用PHP)。

在浏览器中进行以下调用甚至导航到此URL后,响应始终以JSON或其他一些时髦格式返回,从不以XML格式返回:

http://svcs.ebay.com/services/search/FindingService/v1?SECURITY-APPNAME=[removed-for-security]&OPERATION-NAME=findItemsByKeywords&SERVICE-VERSION=1.12.0&RESPONSE-DATA-FORMAT=XML&callback=_cb_findItemsByKeywords&REST-PAYLOAD&keywords=$searchTerm&paginationInput.entriesPerPage=3

有什么想法吗?

编辑:这就是我收到的内容:

_cb_findItemsByKeywords({"findItemsByKeywordsResponse":[{"ack":["Success"],"version":["1.12.0"],"timestamp":["2013-04-23T21:41:13.474Z"],"searchResult":[{"@count":"3","item":[{"itemId":["261205412868"],"title":["Apple iPhone 4 - 32GB - Black (Unlocked) Smartphone"],"globalId":["EBAY-US"],"primaryCategory":[{"categoryId":["9355"],"categoryName":["Cell Phones & Smartphones"]}],"galleryURL":["http:\/\/thumbs1.ebaystatic.com\/m\/my0vy-RgnhVBALirMFhHCaA\/140.jpg"],"viewItemURL":["http:\/\/www.ebay.com\/itm\/Apple-iPhone-4-32GB-Black-Unlocked-Smartphone-\/261205412868?pt=Cell_Phones"],"productId":[{"@type":"ReferenceID","__value__":"99939964"}],"paymentMethod":["PayPal"],"autoPay":["false"],"postalCode":["97215"],"location":["Portland,OR,USA"],"country":["US"],"shippingInfo":[{"shippingServiceCost":[{"@currencyId":"USD","__value__":"0.0"}],"shippingType":["Free"],"shipToLocations":["US"],"expeditedShipping":["true"],"oneDayShippingAvailable":["false"],"handlingTime":["2"]}],"sellingStatus":[{"currentPrice":[{"@currencyId":"USD","__value__":"274.99"}],"convertedCurrentPrice":[{"@currencyId":"USD","__value__":"274.99"}],"sellingState":["Active"],"timeLeft":["P4DT23H13M47S"]}],"listingInfo":[{"bestOfferEnabled":["false"],"buyItNowAvailable":["false"],"startTime":["2013-04-23T20:55:00.000Z"],"endTime":["2013-04-28T20:55:00.000Z"],"listingType":["FixedPrice"],"gift":["false"]}],"returnsAccepted":["false"],"condition":[{"conditionId":["3000"],"conditionDisplayName":["Used"]}],"isMultiVariationListing":["false"],"topRatedListing":["false"]},{"itemId":["111054473885"],"title":["Apple iPhone 3GS - 16GB Black (AT&T) Smartphone (MB715LL\/A) With Original Box"],"globalId":["EBAY-US"],"primaryCategory":[{"categoryId":["9355"],"categoryName":["Cell Phones & Smartphones"]}],"galleryURL":["http:\/\/thumbs2.ebaystatic.com\/m\/mVzC6dpqIgRKIzrUTKqH2SA\/140.jpg"],"viewItemURL":["http:\/\/www.ebay.com\/itm\/Apple-iPhone-3GS-16GB-Black-AT-T-Smartphone-MB715LL-A-Original-Box-\/111054473885?pt=Cell_Phones"],"productId":[{"@type":"ReferenceID","__value__":"101828989"}],"paymentMethod":["PayPal"],"autoPay":["false"],"postalCode":["13323"],"location":["Clinton,NY,USA"],"country":["US"],"shippingInfo":[{"shippingType":["Calculated"],"shipToLocations":["US"],"expeditedShipping":["true"],"oneDayShippingAvailable":["false"],"handlingTime":["2"]}],"sellingStatus":[{"currentPrice":[{"@currencyId":"USD","__value__":"73.0"}],"convertedCurrentPrice":[{"@currencyId":"USD","__value__":"73.0"}],"bidCount":["38"],"sellingState":["Active"],"timeLeft":["P0DT0H0M42S"]}],"listingInfo":[{"bestOfferEnabled":["false"],"buyItNowAvailable":["false"],"startTime":["2013-04-16T21:41:55.000Z"],"endTime":["2013-04-23T21:41:55.000Z"],"listingType":["Auction"],"gift":["false"]}],"returnsAccepted":["false"],"condition":[{"conditionId":["3000"],"conditionDisplayName":["Used"]}],"isMultiVariationListing":["false"],"topRatedListing":["false"]},{"itemId":["111058640858"],"title":["Apple iPhone 4 - 16GB - Black (Verizon)"],"globalId":["EBAY-US"],"primaryCategory":[{"categoryId":["9355"],"categoryName":["Cell Phones & Smartphones"]}],"galleryURL":["http:\/\/thumbs3.ebaystatic.com\/m\/my0vy-RgnhVBALirMFhHCaA\/140.jpg"],"viewItemURL":["http:\/\/www.ebay.com\/itm\/Apple-iPhone-4-16GB-Black-Verizon-\/111058640858?pt=Cell_Phones"],"productId":[{"@type":"ReferenceID","__value__":"101787954"}],"paymentMethod":["PayPal"],"autoPay":["true"],"postalCode":["30213"],"location":["Fairburn,GA,USA"],"country":["US"],"shippingInfo":[{"shippingType":["Calculated"],"shipToLocations":["US"],"expeditedShipping":["true"],"oneDayShippingAvailable":["false"],"handlingTime":["2"]}],"sellingStatus":[{"currentPrice":[{"@currencyId":"USD","__value__":"150.0"}],"convertedCurrentPrice":[{"@currencyId":"USD","__value__":"150.0"}],"sellingState":["Active"],"timeLeft":["P2DT21H31M58S"]}],"listingInfo":[{"bestOfferEnabled":["false"],"buyItNowAvailable":["false"],"startTime":["2013-04-23T19:13:11.000Z"],"endTime":["2013-04-26T19:13:11.000Z"],"listingType":["FixedPrice"],"gift":["false"]}],"returnsAccepted":["false"],"condition":[{"conditionId":["3000"],"conditionDisplayName":["Used"]}],"isMultiVariationListing":["false"],"topRatedListing":["false"]}]}],"paginationOutput":[{"pageNumber":["1"],"entriesPerPage":["3"],"totalPages":["488589"],"totalEntries":["1465767"]}],"itemSearchURL":["http:\/\/www.ebay.com\/sch\/i.html?_nkw=iphone&_ddo=1&_ipg=3&_pgn=1"]}]})

不确定这是什么,因为我已经尝试将其验证为JSON,并且它回来说它无效。

3 个答案:

答案 0 :(得分:2)

您获得的格式是JSONP。从网址中删除&callback=_cb_findItemsByKeywords。然后你会得到xml

这里有一个给你xml的网址:

http://svcs.ebay.com/services/search/FindingService/v1?SECURITY-APPNAME=[removed-for-security]&OPERATION-NAME=findItemsByKeywords&SERVICE-VERSION=1.12.0&RESPONSE-DATA-FORMAT=XML&REST-PAYLOAD&keywords=$searchTerm&paginationInput.entriesPerPage=3

答案 1 :(得分:0)

&responseencoding=XML添加到结尾或网址。

答案 2 :(得分:0)

问:JSON出了什么问题;)?

回答你的问题:

  

http://developer.ebay.com/devzone/finding/Concepts/MakingACall.html

     

默认情况下,XML请求的调用响应是XML格式,但是   如果需要,您可以将NV或JSON指定为响应格式。

以下是eBay网页上的一个例子:

http://svcs.ebay.com/services/search/FindingService/v1?
   OPERATION-NAME=findItemsByKeywords
   &SERVICE-VERSION=1.0.0
   &SECURITY-APPNAME=YourAppID
   &RESPONSE-DATA-FORMAT=XML
   &REST-PAYLOAD
   &keywords=harry%20potter%20phoenix

这是你的榜样:

http://svcs.ebay.com/services/search/FindingService/v1?
  SECURITY-APPNAME=[removed-for-security]
  &OPERATION-NAME=findItemsByKeywords
  &SERVICE-VERSION=1.12.0
  &RESPONSE-DATA-FORMAT=XML
  &callback=_cb_findItemsByKeywords
  &REST-PAYLOAD
  &keywords=$searchTerm&paginationInput.entriesPerPage=3

最显着的差异似乎是你的回调。建议:失去它!