Steam Web API:获取 CSGO 库存/CrossDomainRequest
Steam Web API: Get CSGO inventory/ CrossDomainRequest
我在从本地主机向 http://steamcommunity.com/profiles/{steamid}/inventory/json/730/2
发出 ajax 请求时遇到问题
问题似乎是他们没有启用 CORS headers,所以我必须使用 jsonp。由于 GET 请求 returns json,但我的 ajax 函数需要 json-p 我收到一个错误:
Uncaught SyntaxError: Unexpected token :
2?callback=jQuery22005740937136579305_1452887017109&_=1452887017110:1
我需要这个资源,但我不确定如何解决这个问题。我环顾四周,但没有找到任何与此问题具体匹配的内容。有一些网站能够获取特定用户的库存,所以在某些方面它必须是可能的。
我的 Ajax 电话
$.ajax({
url: "http://steamcommunity.com/profiles/76561198064153275/inventory/json/730/2",
type: 'GET',
dataType: 'jsonp',
success: function(response) {
console.log(response);
if(response.error){
alert(response.error_text);
}else {
console.log("SUCCESS!!");
}
}
});
我找到了解决方法!我正在为我的 Web 应用程序使用 Django,因此我尝试在服务器端发出请求。
我通过pip安装了requests库(库:http://docs.python-requests.org/en/latest/)
在我的 Django 应用程序中,我创建了一个视图,我的 AJAX 请求会调用该视图
def get_steam_inv(request):
user_steam_profile = SteamProfile.objects.get(brokerr_user_id = request.user.id)
r = requests.get("http://steamcommunity.com/profiles/76561198064153275/inventory/json/730/2")
return JsonResponse(r.json())
然后我的 ajax 请求此视图:
$.ajax({
url: "/ajax_get_steam_inv/",
type: 'GET',
success: function(response) {
console.log(response);
// result = JSON.parse(response);
if (response.error){
alert(response.error_text);
} else {
console.log(response);
}
}
});
现在我有了我需要的数据!
我在从本地主机向 http://steamcommunity.com/profiles/{steamid}/inventory/json/730/2
发出 ajax 请求时遇到问题问题似乎是他们没有启用 CORS headers,所以我必须使用 jsonp。由于 GET 请求 returns json,但我的 ajax 函数需要 json-p 我收到一个错误:
Uncaught SyntaxError: Unexpected token :
2?callback=jQuery22005740937136579305_1452887017109&_=1452887017110:1
我需要这个资源,但我不确定如何解决这个问题。我环顾四周,但没有找到任何与此问题具体匹配的内容。有一些网站能够获取特定用户的库存,所以在某些方面它必须是可能的。
我的 Ajax 电话
$.ajax({
url: "http://steamcommunity.com/profiles/76561198064153275/inventory/json/730/2",
type: 'GET',
dataType: 'jsonp',
success: function(response) {
console.log(response);
if(response.error){
alert(response.error_text);
}else {
console.log("SUCCESS!!");
}
}
});
我找到了解决方法!我正在为我的 Web 应用程序使用 Django,因此我尝试在服务器端发出请求。
我通过pip安装了requests库(库:http://docs.python-requests.org/en/latest/)
在我的 Django 应用程序中,我创建了一个视图,我的 AJAX 请求会调用该视图
def get_steam_inv(request):
user_steam_profile = SteamProfile.objects.get(brokerr_user_id = request.user.id)
r = requests.get("http://steamcommunity.com/profiles/76561198064153275/inventory/json/730/2")
return JsonResponse(r.json())
然后我的 ajax 请求此视图:
$.ajax({
url: "/ajax_get_steam_inv/",
type: 'GET',
success: function(response) {
console.log(response);
// result = JSON.parse(response);
if (response.error){
alert(response.error_text);
} else {
console.log(response);
}
}
});
现在我有了我需要的数据!