简体   繁体   English

如何使用jsonp通过Steam API获取CSGO库存?

[英]How to get CSGO Inventory with Steam API using jsonp?

So I'm trying to get a player's CSGO inventory using Valve's API, but I can't get it to work since it's giving me the no 'access-control-allow-origin' header is present on the requested resource. 因此,我试图使用Valve的API获取玩家的CSGO库存,但由于它使我no 'access-control-allow-origin' header is present on the requested resource.因此无法正常工作no 'access-control-allow-origin' header is present on the requested resource. error, so I tried using jsonp but I'm not sure if it supports it. 错误,因此我尝试使用jsonp,但不确定它是否支持它。 So I was wondering how I would get someone's inventory? 所以我想知道如何获取某人的库存? A ton of other sites can get it but I don't know what I need to do. 很多其他站点都可以得到它,但是我不知道该怎么做。 Any help is appreciated :) 任何帮助表示赞赏:)

I'm using javascript/jQuery if that helps at all 我正在使用javascript / jQuery,如果有帮助的话

You cant get access to the inventory via jsonp because steam disallows CORS requests (they need to set the headers). 您无法通过jsonp访问清单,因为Steam不允许CORS请求(它们需要设置标头)。

Since steam is not providing an option to enable this you need to proxy the inventory request through your own server. 由于Steam没有提供启用此功能的选项,因此您需要通过自己的服务器代理库存请求。

Basic structure 基本结构

So you need to write your own REST API Proxy to achieve this: 因此,您需要编写自己的REST API代理来实现此目的:

  1. Get Request from your application with the steam community as parameter. 使用Steam社区作为参数从您的应用程序获取请求。 Should be look something like localhost:8080/inventory/76561197961239110 应该看起来像localhost:8080 / inventory / 76561197961239110
  2. On your server make a request to this url: http://steamcommunity.com/inventory/76561197961239110/570/2?l=english&count=5000 在您的服务器上请求以下网址: http : //steamcommunity.com/inventory/76561197961239110/570/2? l= english& count= 5000
  3. Get the response and probably even edit it to your needs (like delete unnecessary properties). 获取响应,甚至可以根据需要对其进行编辑(例如删除不必要的属性)。
  4. Return the response in JSON to your Frontend application. 将JSON中的响应返回到您的Frontend应用程序。 You can also enable jsonp there (read for example this question and the answers). 您还可以在此处启用jsonp(例如,阅读此问题和答案)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM