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

Let me start off with saying I just figured out how to use JQuery's "$.ajax()" just a fe

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744848984a4597014.html

相关推荐

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

    Let me start off with saying I just figured out how to use JQuery's "$.ajax()" just a fe

    2天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信