如何获得蒸汽API来工作吗?蒸汽、如何获得、工作、API

2023-09-11 01:16:17 作者:帅气的五个字昵称

让我有说我只是想出了如何使用jQuery的$。阿贾克斯()短短数天前开始。我已经能够读取本地的.xml和.json文件。

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.

另外,我想通了如何使用谷歌地图API导入动态和静态地图。 (只是继谷歌文档)

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

现在,我有一个主意,用蒸汽的ID为学校的项目,但我不断收到此错误:

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. 

(我拿出钥匙,并将生成的关键是假设允许访问 http://local.mysite.com )

下面是我的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.

推荐答案

请参阅这个答案和的在这里职位。欲了解更多的背景访问 MDN 。 从本质上讲,你正在运行到一个安全问题,即浏览器不会让你做出从 http://local.mysite.com 请求 http://api.steampowered.com

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.

您是否有访问服务器?而不是让一个请求是这样的:浏览器 - &GT; steampowered 你可以这样浏览器的请求 - &GT;你的服务器 - &GT; 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.

什么语言/框架您运行的是,我们可以给你比如code。

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