2013-04-23 4 views
1

Я пытаюсь сделать вызов API eBay и вернуть результаты в формате XML (я использую PHP).eBay API не возвращает формат XML

При принятии следующего вызова или даже навигаций по этому 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 

Есть мысли?

EDIT: Это то, что я получаю:

_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 и возвращается, говоря, что это не действует.

ответ

2

Формат, который вы получили, это JSONP. Удалите &callback=_cb_findItemsByKeywords с URL-адреса. Тогда вы получите XML

Здесь приходит URL, который дает вам 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 
+0

Это сработало. Благодаря! – Anterres

+0

Добро пожаловать. Похож на ошибку в ebay api, что выходной формат зависит от наличия параметра. Вы указали '& RESPONSE-DATA-FORMAT = XML', что должно быть достаточно. Однако теперь он работает для вас. – hek2mgl

0

Добавить &responseencoding=XML до конца или URL.

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 

Наиболее существенное различие, как представляется, ваш обратный вызов. ПРЕДЛОЖЕНИЕ: потеряйте!

+0

Я не смог разобрать JSON с json_decode/json_encode, иначе я бы, конечно, попытался! – Anterres

Смежные вопросы