我很困惑..请帮帮我
当我提出ebay-search-Request时:
http://svcs.ebay.com/services/search/FindingService/v1?OPERATION-NAME=findItemsByKeywords&SERVICE[...]
在我的浏览器中,它显示了一个JSON。我在我的网站空间中将JSON复制到名为v1的文件中:
http://bloxxer.net/autentik/v1?OPERATION-NAME=findItemsByKeywords&SERVICE-VERSION=1.0.0&SECURITY-APPNAME=blabla;D&GLOBAL-ID=EBAY-US&RESPONSE-DATA-FORMAT=JSON&REST-PAYLOAD&keywords=fahrrad&paginationInput.entriesPerPage=3&itemFilter(0).name=MaxPrice&itemFilter(0).value=25&itemFilter(0).paramName=Currency&itemFilter(0).paramValue=EUR&itemFilter(1).name=ListingType&itemFilter(1).value(0)=AuctionWithBIN&itemFilter(1).value(1)=FixedPrice
我的网站空间的$ http.get-Request为我提供了JSON:
var AutApp = angular.module('AutApp', []);
AutApp.controller('ctrl', function($scope,$http) {
$scope.search_ebay = function(keys) {
// var url = "http://svcs.ebay.com/services/search/FindingService/v1";
var url = "http://bloxxer.net/autentik/v1";
url += "?OPERATION-NAME=findItemsByKeywords";
url += "&SERVICE-VERSION=1.0.0";
url += "&SECURITY-APPNAME=ID"; // doesnt work on ebay without ID
url += "&GLOBAL-ID=EBAY-US";
url += "&RESPONSE-DATA-FORMAT=JSON";
url += "&REST-PAYLOAD";
url += "&keywords=fahrrad";// + keys;
url += "&paginationInput.entriesPerPage=3";
$http.get(url).
success(function(data) {
var items = data.findItemsByKeywordsResponse[0].searchResult[0].item || [];
var html = [];
$scope.ebay_suchergebnis='<table width="100%" border="0" cellspacing="0" cellpadding="3"><tbody>';
for (var i = 0; i < items.length; ++i) {
var item = items[i];
var title = item.title;
var pic = item.galleryURL;
var viewitem = item.viewItemURL;
if (null != title && null != viewitem) {
$scope.ebay_suchergebnis+='<tr><td><a href="' + viewitem + '" target="_blank">' + '<img src="' + pic + '" border="0">' + title + '</a></td></tr>';
}
}
})
.
error(function(data,status) {
$scope.ebay_suchergebnis=data+"#"+status;
});
};
$scope.sucheingabe="";
});
但是如果我将$ http.get-Request更改为svcs.ebay.com(带有我的ID),它会给我“null#0”。
有人有想法吗?谢谢!
答案 0 :(得分:1)
解决方案非常简单..没有cors和co ..只是绕道而行:
<?php
$url = "http://svcs.ebay.com/services/search/FindingService/v1";
$url .= "?OPERATION-NAME=findItemsByKeywords";
$url .= "&SERVICE-VERSION=1.0.0";
$url .= "&SECURITY-APPNAME=YOUR_ID_IN_EBAY";
$url .= "&GLOBAL-ID=EBAY-US";
$url .= "&RESPONSE-DATA-FORMAT=JSON";
$url .= "&REST-PAYLOAD";
$url .= "&".$_SERVER["QUERY_STRING"];
$json = file_get_contents($url);
echo $json;
javascript:
AutApp.controller('ctrl', function($scope,$http) {
$scope.search_ebay = function(keys,anzahl) {
var url='http://YourDomain.com/json_abfragen.php?keywords='+keys+"&paginationInput.entriesPerPage="+anzahl;
$http.get(url).
success(function(data) {
var items = data.findItemsByKeywordsResponse[0].searchResult[0].item || [];
var ebay_suchergebnis='<table><tr>';
for (var i = 0; i < items.length; ++i) {
var item = items[i];
if (null != item.title && null != item.viewItemURL) {
ebay_suchergebnis+='<td><a href="' + item.viewItemURL + '" target="_blank"><img src="'+item.galleryURL+'"><br>' + items[i].title + '</a></td>';
}
}
ebay_suchergebnis+='</tr></table>';
document.getElementById('here').innerHTML=ebay_suchergebnis;
})
.
error(function(data,status) {
// errorprocessing
});
};
});