错误的GET请求汽市场 [英] Error on GET request to steam market

查看:148
本文介绍了错误的GET请求汽市场的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个GET请求来获取蒸汽市场上单个项目该项目的价格信息。

下面是确切的angularJS脚本我使用的:

 <脚本>
VAR应用= angular.module('CSGO',[]);
app.controller('MainCtrl',函数($范围,$ 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​​ =响应;
        的console.log(响应);
    });
});
< / SCRIPT>

当我尝试做这在我的浏览器我得到:

 未捕获的SyntaxError:意外的令牌:货币= 3及的appid = 730安培; market_​​hash_name = StatTrak™P250 |?钢铁中断(新厂):1

在我的chrome浏览器的控制台。然后我点击错误消息中的链接(货币= 3及的appid = 730安培; market_​​hash_name = StatTrak™P250 |钢中断(新厂):1)

和它需要我的电话线为:

  {成功:真的,LOWEST_PRICE:1,09和放大器;#8364;,卷:348,median_price:1,01&安培; #8364;}

所以,我居然得到的信息,但是它给出了一个错误,并强调在红JSON响应。任何人都知道这个问题?

我使用的NodeJS,前preSS,和棱角分明。

编辑:

我尝试了不同的网址: https://angularjs.org/ greet.php回调= JSON_CALLBACK&放大器;名称=超级%20Hero

和其与此URL的工作。因此,林不知道为什么我想请求原始URL是行不通的。上任何想法?


解决方案

当您使用 JSONP ,它应该调用 JSON_CALLBACK()来处理结果。您可以参考角JSONP文件了解更多信息,还提供href=\"http://plnkr.co/edit/?p=$p$pview\" rel=\"nofollow\">现场演示一个 JSON_CALLBACK 被使用。

所以你的情况,你应该叫像下面

<$p$p><$c$c>$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​​ =响应;
    的console.log(响应);
});

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

更新

我只看到蒸汽社区


  

有一个缺乏对JSONP协议的支持和API的
  可接受的使用政策要求,API密钥不被共享。
  如上所述,使用JavaScript文件内这个API密钥(这是
  在客户端全部源下载)是针对策略
  该阀提供了


他们不支持 JSONP ,他们不支持 CORS 无论是。看起来你可以从角访问蒸汽API。

I am attempting to do a GET request to get the item price info for a single item on the steam market.

Here is the exact angularJS script I am using:

<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>

When I try to do this in my browser I get:

Uncaught SyntaxError: Unexpected token : ?currency=3&appid=730&market_hash_name=StatTrak™ P250 | Steel Disruption (Factory New):1

Inside my chrome browser console. I then click the link in error message (?currency=3&appid=730&market_hash_name=StatTrak™ P250 | Steel Disruption (Factory New):1)

And it takes me to a line that is:

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

So I actually get the information, but it gives an error and underlines the JSON response in red. Anyone know the issue?

I am using nodejs, express, and angular.

EDIT:

I tried a different URL: https://angularjs.org/greet.php?callback=JSON_CALLBACK&name=Super%20Hero

And it worked with this URL. So im not sure why the original URL I am trying to request is not working. Any ideas on that?

解决方案

When you are using JSONP, it should call JSON_CALLBACK() to process the results. You can refer to Angular JSONP document for more information, it also provides a live demo of how JSON_CALLBACK is used.

So in your case, you should call like below

$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); 
});

If you server handle JSON_CALLBACK correctly, all errors should be gone.

Update

I just look into the 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

They don't support JSONP, and they don't support CORS either. It looks like you can access steam api from Angular.

这篇关于错误的GET请求汽市场的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆