1

我正在尝试调用 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,但它返回说它无效。

4

3 回答 3

2

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

这是为您提供 xml 的 url:

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
于 2013-04-23T21:42:29.513 回答
0

添加&responseencoding=XML到末尾或 URL。

于 2013-04-23T21:43:00.387 回答
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

最显着的区别似乎是您的回调。建议:丢掉它!

于 2013-04-23T21:46:12.180 回答