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

javascript - How do I get the steam API to work? - Stack Overflow

programmeradmin3浏览0评论

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 /?key=[MY_SECRET_KEY]2&steamid=76561197960435530&relationship=friend. Origin  is not allowed by Access-Control-Allow-Origin. 

(I took out the key, and the generated key is suppose to allow access to )

Here is my code:

    <script type="text/javascript">
        $.ajax({
            url: "/?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.

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./ISteamUser/GetFriendList/v0001/?key=[MY_SECRET_KEY]2&steamid=76561197960435530&relationship=friend. Origin http://local.mysite. 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.)

Here is my code:

    <script type="text/javascript">
        $.ajax({
            url: "http://api.steampowered./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.

Share Improve this question asked Oct 27, 2013 at 22:11 Steven RogersSteven Rogers 2,0045 gold badges26 silver badges48 bronze badges 1
  • 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 Commented Oct 27, 2013 at 22:27
Add a ment  | 

1 Answer 1

Reset to default 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. to http://api.steampowered..

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.

发布评论

评论列表(0)

  1. 暂无评论