对蒸汽市场的GET请求错误
我试图做一个GET请求来获取蒸汽市场上的单个项目的物品价格信息。
这里是我正在使用的确切的angularJS脚本:
<script> var app = angular.module('csgo', []); app.controller('MainCtrl', function($scope, $http) { $http.jsonp("http://steamcommunity.com/market/priceoverview/?currency=3&appid=730&market_hash_name=StatTrak%E2%84%A2%20P250%20%7C%20Steel%20Disruption%20%28Factory%20New%29").success(function(response) { $scope.values = response; console.log(response); }); }); </script>
当我尝试在浏览器中执行此操作时,我得到:
Uncaught SyntaxError: Unexpected token : ?currency=3&appid=730&market_hash_name=StatTrak™ P250 | Steel Disruption (Factory New):1
在我的Chrome浏览器控制台中。 然后点击错误信息中的链接(?currency = 3&appid = 730&market_hash_name = StatTrak™P250 | Steel Disruption(Factory New):1)
这需要我的一条线是:
{"success":true,"lowest_price":"1,09€ ","volume":"348","median_price":"1,01€ "}
所以我实际上得到的信息,但它给出了一个错误,并强调红色的JSON响应。 有人知道这个问题吗?
我使用nodejs,express和angular。
编辑:
我尝试了一个不同的url: https : //angularjs.org/greet.php?callback=JSON_CALLBACK&name=Super%20Hero
它和这个URL一起工作。 所以即时通讯不知道为什么我想要请求的原始url不工作。 任何想法呢?
当你使用JSONP
,它应该调用JSON_CALLBACK()
来处理结果。 您可以参阅Angular JSONP文档以获取更多信息,还提供了如何使用JSON_CALLBACK
的现场演示 。
所以在你的情况下,你应该打电话如下
$http.jsonp("http://steamcommunity.com/market/priceoverview/?callback=JSON_CALLBACK¤cy=3&appid=730&market_hash_name=StatTrak%E2%84%A2%20P250%20%7C%20Steel%20Disruption%20%28Factory%20New%29").success(function(response) { $scope.values = response; console.log(response); });
如果服务器正确处理JSON_CALLBACK
,则所有错误都应该消失。
更新
我只是看看Steam社区
缺乏对JSONP协议的支持,并且API的可接受的使用策略要求API密钥不被共享。 如上所述,在JavaScript文件(由客户端完全下载)中使用此API密钥将违反Valve所提供的政策
他们不支持JSONP
,也不支持CORS
。 它看起来像你可以从Angular访问steam api。