问题
I got an issue with my Angular request.
angular.module('google-chart-example', []).controller("MainCtrl", function ($scope,$http,$log) {
$scope.infos = "";
//$http.get('http://ip.jsontest.com')
//$http.get('https://finance.google.com/finance/info?q=TSE:PXT')
$http.get('http://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.quotes where symbol in ("AAPL")&format=json')
.success(function(data) {
//alert ("toto");
$scope.infos = data;
})
.error(function(data) {
alert ("data="+data);
$scope.infos = data;
});
});
$http.get('http://ip.jsontest.com') ==> this is one is working fine .. no trouble
$http.get('https://finance.google.com/finance/info?q=TSE:PXT') ==> This one is not working, i got no result
$http.get('http://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.quotes where symbol in ("AAPL")&format=json') ==> This one, i got an answer but it's telling me the table doesn't exist : {"error":{"lang":"en-US","description":"No definition found for Table yahoo.finance.quote"}} (I tried quote ans quotes: same result)
Any idea why I'm not able to retrieve my prices?
My HTML:
<html xmlns="http://www.w3.org/1999/html">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.18/angular.js"</script>
<script src="index3.js"></script>
</head>
<body ng-app="google-chart-example" ng-controller="MainCtrl">
coucou <br>
{{infos}}
</body>
</html>
回答1:
You tring to query yahoo.finance.quotes, however the query need to be on yahoo.finance.quote
select * from yahoo.finance.quote
回答2:
Use the yql console to build queries, it'll give you a REST QUERY url that you can use to make http GET requests, for your example:
https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22AAPL%22)&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=
https://developer.yahoo.com/yql/console
回答3:
For Yahoo i was missing the community table parameter : &env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys
it works now, thanks.
来源:https://stackoverflow.com/questions/25337392/issue-with-angularjs-and-financial-quote