1

Let me start off with saying I just figured out how to use JQuery's "$.ajax()" just a few days ago. I've been able to read local .xml and .json files.

Also, I've figured out how to use the google maps API to import dynamic and static maps. (just following the google documentation)

Now, I had an idea to use steam IDs for a school project, but I keep getting this error:

XMLHttpRequest cannot load http://api.steampowered.com/ISteamUser/GetFriendList/v0001/?key=[MY_SECRET_KEY]2&steamid=76561197960435530&relationship=friend. Origin http://local.mysite.com is not allowed by Access-Control-Allow-Origin. 

(I took out the key, and the generated key is suppose to allow access to http://local.mysite.com)

Here is my code:

    <script type="text/javascript">
        $.ajax({
            url: "http://api.steampowered.com/ISteamUser/GetFriendList/v0001/?key=[MY_SECRET_KEY]&steamid=76561197960435530&relationship=friend",
            dataType: "json",
            success: function(data){
                console.log(data);
            },
            error: function(req,text,error){
                console.log(text);
                console.log(error);
                console.log("DIDN'T WORK!")
            }
        });
    </script>

Does anybody know what's going on? I can't seem to get this to work.

Steven Rogers
  • 1,874
  • 5
  • 25
  • 48
  • So "[MY_SECRET_KEY]" is your generated key? It looks like you should be replacing "[MY_SECRET_KEY]" which a key which GetFriendList can interpret. – Ben Smith Oct 27 '13 at 22:27

1 Answers1

3

See this answer and the posts here. For more background visit mdn. Essentially you're running into a security issue where the browser won't allow you to make a request from http://local.mysite.com to http://api.steampowered.com.

Do you have access to a server? Instead of making a request like this: browser -> steampowered you can make a request like this browser -> your server -> steampowered.

You're going to want to create an endpoint on your server (so that it's in your domain) that you can send a request to, that will in turn send a request to steam powered.

What language / framework are you running and we can give you example code.

Community
  • 1
  • 1
ibash
  • 1,477
  • 17
  • 31
  • I'm running a virtual server on Apache 2 on a Mac. I'm still somewhat new to this, and I don't own an actual server. Thank you very much for your help. – Steven Rogers Oct 27 '13 at 22:52
  • Fair enough, do you have any backend code running now? You can still do it on your mac. If you just have a static site right now you'll have to introduce some backend code. – ibash Oct 28 '13 at 00:01
  • I've never done any back-end code before. I'm about to learn Python, but all I know right now is how to load Javascript into a browser and run it through that way. – Steven Rogers Oct 28 '13 at 02:51