最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - Steam API Get SteamID using Javascript - Stack Overflow

programmeradmin1浏览0评论

Been running into what appears to be the Same Origin Policy which is causing quite some headache!

To cut to the chase, I am essentially trying to acquire a user's steam64id when only supplied their username.

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

And the steamid I need is right at the top. So I figured I would use JQuery Ajax to acquire this and parse out the id I need for later usage (steamapi usage requires the steam64id) as follows. Here is a snippet of the code in question:

$.ajax({
url: "/?xml=1",
datatype: "xml",
plete: function()
{
    alert(this.url)
},
success: parse
});

function parse(xml)
{
    alert("parsing");
    _steamID = $(xml).find("steamID64").text();
}

The problem here is while I do get the alert for the pletion, I never see "parsing". Ever. It never gets that callback, which leads me to believe I am running into the SOP (same origin policy).

Am I approaching this the wrong way, is there a workaround?

Thanks!

Been running into what appears to be the Same Origin Policy which is causing quite some headache!

To cut to the chase, I am essentially trying to acquire a user's steam64id when only supplied their username.

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

http://steammunity./id/emperor_jordan?xml=1

And the steamid I need is right at the top. So I figured I would use JQuery Ajax to acquire this and parse out the id I need for later usage (steamapi usage requires the steam64id) as follows. Here is a snippet of the code in question:

$.ajax({
url: "http://steammunity./id/emperor_jordan/?xml=1",
datatype: "xml",
plete: function()
{
    alert(this.url)
},
success: parse
});

function parse(xml)
{
    alert("parsing");
    _steamID = $(xml).find("steamID64").text();
}

The problem here is while I do get the alert for the pletion, I never see "parsing". Ever. It never gets that callback, which leads me to believe I am running into the SOP (same origin policy).

Am I approaching this the wrong way, is there a workaround?

Thanks!

Share Improve this question asked Oct 31, 2012 at 3:32 Jordan JohnsJordan Johns 7452 gold badges10 silver badges20 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

Correct. You are running into the same-origin policy:

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

and it looks like Steam does not offer a cross-origin solution like JSONP. That means you're back to the old-but-reliable solution: fetch the data on your server, not in the browser.


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

You need to create a proxy server in Heroku in order to get the data. Cors is restricting us to call the data directly to our browser not server to server interaction. So we need a proxy server to send the requests and receive the data on our behalf. It's working for me.

Thanks in advance.

发布评论

评论列表(0)

  1. 暂无评论