2

I'm trying to create a web application that utilizes steam web apis, and overall I'm basically very confused as to how start this application.This question basically outlines my problem, and I don't know how exactly to create endpoints and solve this problem.

Currently I have Apache Tomcat for my web server, and I'm writing all the html/css/javascript code in Notepad++. I don't want to use jQuery, because I don't know if I need to. Now all I want to do is just grab data from steam's apis.

For example, using this api:

http://api.steampowered.com/ISteamUser/GetFriendList/v0001/?key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&steamid=76561197960435530&relationship=friend

I just want to grab a user's friend list. The problem is, as in the question I linked above, I can't make calls to steam apis from my own site, and I don't know how to create an endpoint on my server and fix this problem.

Any help is greatly appreciated. I'm new to all of this, and it'd definitely confusing as hell.

Community
  • 1
  • 1
Vishwa Iyer
  • 841
  • 5
  • 14
  • 33
  • If your application is in html/css/javscript could you use Apache? There is a mod_proxy module in Apache that might work for this. Otherwise something in Java to proxy the requests – Dustin Butler Aug 25 '14 at 02:31
  • I am using apache now, so what is the mod_proxy module? I am sorry I'm new to this. – Vishwa Iyer Aug 25 '14 at 11:16

2 Answers2

1

You can proxy the requests from your server to the steam site using mod_proxy. First need to enable rewrite and mod proxy in Apache

a2enmod rewrite
a2enmod proxy
apache2ctl reload

Let's assume your site is www.example.com and the web root is /var/www on your server. Create a directory /var/www/steamapi. In this directory create a file named .htaccess with the following

RewriteEngine On
RewriteRule ^(.*)$ http://api.steampowered.com/$1 [P]

The [P] tells Apache to proxy the request. Now instead of making request to api.steampower.com use absolute url below in your XHR/AJAX url parameter

/steamapi/ISteamUser/GetFriendList/v0001/?key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&steamid=76561197960435530&relationship=friend

Apache will rewrite the request to the URI below and proxy the results back to you. Your browser won't complain because you are making a request to the same domain.

http://api.steampowered.com/ISteamUser/GetFriendList/v0001/?key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&steamid=76561197960435530&relationship=friend
Dustin Butler
  • 818
  • 7
  • 22
  • For the request, can I use this code: `var xhr = new XMLHttpRequest(); xhr.open("GET", "http://api.steampowered.com/ISteamUser/GetFriendList/v0001/?key="+API_KEY+"&steamid=76561198041707719&relationship=all", false); xhr.send(); var data = JSON.parse(xhr.responseText); ` – Vishwa Iyer Aug 26 '14 at 01:03
  • No, that is the reason for the proxy, your page can't make requests to api.steampowered.com because it was loaded via www.example.com or whatever your site is. Your request would be xhr.open("GET", "/steamapi/ISteamUser/GetFriendList/v0001/?key="+API_KEY+"&ste‌​amid=76561198041707719&relationship=all", false); If setup properly Apache will turn that into the "real" request and give you the result. – Dustin Butler Aug 26 '14 at 17:14
  • I'm not using a website (because I haven't bought a domain) and this is the site I use: `localhost/phishing/example.php`, so how do I add a directory? – Vishwa Iyer Aug 28 '14 at 01:44
  • Looks like your running Apache locally. The instructions are the still the same. You need to know where your web root is on your computer. It's /var/www by default. So in your example above the directory would be /var/www/phishing. You would add the directory at /var/www/steamapi. What OS are you running? – Dustin Butler Aug 28 '14 at 01:52
  • I am running Windows 8. Also, I'm using xampp, and it says in the http.conf that my document root is htdocs, which is the folder that I have saved my phishing folder in. Should I create the steampi folder there as well. – Vishwa Iyer Aug 28 '14 at 02:06
  • Yes that's the document root so htdocs/steamapi. I've never used Apache on Windows so you'll need to look up how to enable the mod_rewrite and mod_proxy Apache modules – Dustin Butler Aug 28 '14 at 02:12
  • I've already enabled them. Also, does the file created in the steamapi folder have the extension .htaccess or is called htaccess? – Vishwa Iyer Aug 28 '14 at 02:14
  • It's called .htaccess (including the dot) It's a specially named file that Apache looks for. In Linux files with names starting with a dot are hidden which is the reason for starting it with a dot. – Dustin Butler Aug 28 '14 at 02:19
  • So I shouldn't name it anything? If I do that windows says it cannot save the file because it isn't named. – Vishwa Iyer Aug 28 '14 at 02:34
  • http://superuser.com/questions/56562/how-do-i-rename-a-file-to-htaccess-in-windows-7 – Dustin Butler Aug 28 '14 at 03:05
  • How would I add another site? – Varun Iyer Aug 28 '14 at 11:48
  • Your question is pretty vague. Are you talking about another site that provides an API? I don't want to make this comment area into a chat box. Either this solution works or it doesn't. – Dustin Butler Aug 28 '14 at 14:38
  • Yes it works, but I need to use another api from another site. – Vishwa Iyer Aug 29 '14 at 00:03
0

As far as I'm aware for Steam's public APIs they shouldn't need a proxy as the above answer suggests, to do AJAX requests (which is what I assume you are doing), since they surely must implement CORS. Besides this is merely a browser restriction and shouldn't affect anything server side.

The restriction Dustin is trying to explain how to get around is to do with making an AJAX request to a site on a domain different to the one you are requesting that doesn't allow CORS (Cross Origin Resource Sharing). Hence a website would send the data to a proxy server set up to make the request on its behalf and return the data.

Can you elaborate what sort of errors you are getting when trying to make a request?

I'm assuming you are using the APIs found here, https://developer.valvesoftware.com/wiki/Steam_Web_API#GetPlayerSummaries_.28v0001.29

In which case I have to ask, if you see where all the Xs are, these are place holders in that URI. Instead of the Xs you should have a Steam Web API key which you can sign up for from here:

https://steamcommunity.com/dev/apikey

I'm not sure the domain name is that important when signing up since I've repurposed keys before.

Note that Valve's public APIs are quite limited and a number of the libraries floating around on the web don't use them, but instead have either reverse engineered Valve's Oauth login code for their main site to use privately, undocumented web APIs, or they have reverse engineered the desktop client itself somehow.

Astridax
  • 159
  • 1
  • 6
  • I'm not familiar with Steam APIs or if they support jsonp. With jsonp ajax calls you can also make request to a different domain. – Dustin Butler Sep 22 '14 at 17:20