javascriptopenidsteamsteam-web-api

Get steamID with Steam API using javascript


First off sorry if this question is a 'bad' one; I am very new to the world of web apps, API's and Javascript.

As the title says I am trying to get a user's steamID using the Steam API using javascript.

This is for a web app that needs to get information about the games a user plays. (Which from my understanding is only obtainable using this special ID.)

My initial thoughts on how to do this would be to use openID so that the user gives Steam their info and the ID is returned to my app.

I have seen that there are lots of examples of this using php; however, because of project requirements, everything must be run in the browser. There is no backend server to even run php on so it is not an option what so ever.

I have spent a better part of a day trying to figure this out and have made no real progress, everything seems to lead back to using php. (maybe what I need under my requirements is not possible?) So an example or anything really would be much appreciated.


Solution

  • welcome to Stack Overflow I can see you are confused as to where to start or progress so here is a basic roadmap:

    1. You will need to contact Steam to get an API key first.
    2. Next part is more tricky for a beginner. You will need to get npm, which is a package manager for node.js programs and libraries. Effectively it's a large library of javascript programs which you can import into your own program to do things with. One of these so called "packages" is openid-client, which is an implementation of openID that you can add to your site. Users click on the openID button on your site, it redirects them to steam servers, they login, then your site gets their info without leaking their username or password to you.
    3. Now that you have both the steamID and your API Key your program can input these two into the url steam provides to get owned games. You can input this completed url into fetch or axios (another npm package that can request data from servers) and it will respond with the user's owned games in json format.

    Here are a list of resources in order to get you started:

    1. https://steamcommunity.com/dev
    2. https://nodejs.org/en/
    3. https://www.npmjs.com/package/openid-client
    4. https://www.npmjs.com/package/node-fetch OR https://www.npmjs.com/package/axios
    5. https://developer.valvesoftware.com/wiki/Steam_Web_API#GetOwnedGames_.28v0001.29

    I suggest reading the documentation in each of these links and seeing if there is any youtube tutorials that try and do what you are doing with these technologies to help you implement them as a newbie. Overall there is a lot to learn on each of these technologies but as long as you orient yourself using guides or tutorials you will succeed. Good luck.