简体   繁体   中英

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. error, so I tried using jsonp but I'm not sure if it supports it. 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

You cant get access to the inventory via jsonp because steam disallows CORS requests (they need to set the headers).

Since steam is not providing an option to enable this you need to proxy the inventory request through your own server.

Basic structure

So you need to write your own REST API Proxy to achieve this:

  1. Get Request from your application with the steam community as parameter. Should be look something like 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
  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. You can also enable jsonp there (read for example this question and the answers).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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