我在使用API时遇到问题
问题描述:
我在使此API工作时遇到问题。我在使用API时遇到问题
我对Google Finance API使用了相同的代码,并且完美地工作。问题是我只能获得少量的股票,而从长远来看,我需要运行12000只股票(如果可能的话)。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
var temp = [];
$(document).ready(function(){
stockInformation();
setInterval(stockInformation, 5000);
});
function stockInformation()
{
$.ajax({
url:"https://api.website.com/public/user/token/stock/SDRL/quote",
dataType:"jsonp",
jsonp:"callback",
jsonpCallback:"quote"
});
var i = 0; var j = 0;var status = "";
quote = function(data){
var output = "<table>"
$.each(data, function(key, value){
if (value.l_cur > temp[j])
status = "<td style=color:green>Up</td>";
else if (value.l_cur < temp[j])
status = "<td style=color:red>Down</td>";
else
status = "<td>Same</td>";
j++;
output += "<tr><td>" + value.t + "</td><td>" + value.l_cur + "</td>" + status + "</tr>";
temp[i] = value.l_cur;i++;
})
output += "</table>";
$("#result").html(output);
}
}
</script>
<div id="result"></div>
这就是API的回报(不与上面的代码):
{"timestamp":"1503691321","datetime":"2017-08-25 16:02:01 (UTC)","price":"6.17","price change":"0.12","price pct change":"1.98","open":"6.09","volumn":"1852887","low":"6.00","high":"6.22","currency":"USD"}
答
很多的谷歌API的限制请求的数量,你可以在给定时间内做出。有时甚至低至每月50个,取决于api和请求的类型。它看起来不像你在代码中使用api的方式有什么问题。 你可以通过分页来解决这个问题。从30开始一次,然后当你的用户点击下一个按钮或滚动到页面的末尾,然后去获得下一个30.
那么问题是与API本身?我们怎么可能帮助你呢? – lumio
很可能api会有一些限速的时间,12,000是很少的一小部分要求。你应该查看API的文档,看看它是否有选项来指定你想要在一个请求中接收的项目数量,或者如何请求多个报价 –
这没有奏效..:/ API的问题将会只返回1结果,即使我尝试通过url中的股票代码循环不同的符号。我相信这个api没有限制。 –