Steam Market 的 GET 请求错误

Error on GET request to steam market

我正在尝试执行 GET 请求以获取 Steam 市场上单个商品的商品价格信息。

这是我正在使用的 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 浏览器控制台中。然后我单击错误消息中的 link (?currency=3&appid=730&market_hash_name=StatTrak™ P250 | Steel Disruption (Factory New):1)

它把我带到一行:

{"success":true,"lowest_price":"1,09&#8364; ","volume":"348","median_price":"1,01&#8364; "}

所以我实际上得到了信息,但它给出了一个错误并用红色强调了 JSON 响应。有人知道这个问题吗?

我正在使用 nodejs、express 和 angular。

编辑:

我尝试了不同的 URL:https://angularjs.org/greet.php?callback=JSON_CALLBACK&name=Super%20Hero

它与这个 URL 一起工作。所以我不确定为什么我尝试请求的原始 URL 不起作用。有什么想法吗?

当你使用JSONP时,它应该调用JSON_CALLBACK()来处理结果。 JSON_CALLBACK的使用方法可以参考Angular JSONP document for more information, it also provides a live demo

所以在你的情况下,你应该像下面这样调用

$http.jsonp("http://steamcommunity.com/market/priceoverview/?callback=JSON_CALLBACK&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); 
});

如果您的服务器处理 JSON_CALLBACK 正确,所有错误都应该消失。

更新

我只是看看 Steam Community

There is a lack of support for the JSONP protocol and the API's acceptable usage policy requires that the API key is not to be shared. As described, using this API key inside of a Javascript file (which is downloaded in full source by the client) would be against the policy that Valve has provided

他们不支持JSONP,他们也不支持CORS。您似乎可以从 Angular.

访问 Steam api