Steam API Get SteamID Using Javascript

I came across what seems to be the same origin policy that causes some headache!

To abort the chase, I essentially try to acquire the steam64id user when I just provide my username.

For example, my username is: "Emperor_Jordan" I would go to:

http://steamcommunity.com/id/emperor_jordan?xml=1

And I need a couple upstairs. So I decided that I would use jQuery Ajax to get this and analyze the identifier I need for later use (using steamapi requires steam64id) as follows. Here is the code snippet in question:

$.ajax({ url: "http://steamcommunity.com/id/emperor_jordan/?xml=1", datatype: "xml", complete: function() { alert(this.url) }, success: parse }); function parse(xml) { alert("parsing"); _steamID = $(xml).find("steamID64").text(); } 

The problem is here, when I get a warning about completion, I never see "parsing". Ever. It never gets this callback, which leads me to believe that I came across SOP (same origin policy).

I approach this incorrectly, is there a workaround?

Thanks!

+4
source share
1 answer

Right. You use a policy of the same origin:

 XMLHttpRequest cannot load http://steamcommunity.com/id/emperor_jordan/?xml=1. Origin http://fiddle.jshell.net is not allowed by Access-Control-Allow-Origin. 

and it looks like Steam doesn't offer a cross-starter solution like JSONP . This means that you are back to the old, but reliable solution: select the data on your server, and not in the browser.


Some relevant Steam Web API feedback: https://developer.valvesoftware.com/wiki/Steam_Web_API/Feedback#API_Considerations_for_Web_Developers

+5
source

Source: https://habr.com/ru/post/1443140/


All Articles