Angular JS 中的 Steam Web API:GetAppList JSON 和 $http.jsonp 问题

Steam Web API in Angular JS: Issue with the GetAppList JSON and $http.jsonp

希望你一切都好。我正在从事一个涉及在 angular JS 中使用 Steam Web API 的项目。我正在尝试从此 URL 获取数据:

http://api.steampowered.com/ISteamApps/GetAppList/v2

当我 运行 我的代码在 Google Chrome 中时,它显示:

Uncaught SyntaxError: Unexpected token :

我知道 CORS 存在这个问题(有些网站不能很好地使用它,所以我正在尝试使用 JSONP 来解决这个问题。我是否遗漏了什么或做错了什么?

亲切的问候,

阿迪

这是相关的代码片段(根据 Steam Web API 条款,我已经排除了我的 API 密钥):

var steam_api = "https://api.steampowered.com/ISteamApps/GetAppList/v2";
steam_api += "?key=mySteamKey";
steam_api += "&format=json&callback=JSON_CALLBACK";

$scope.steamGames = {};
  $http.jsonp(steam_api)
  .success(function(data, status, headers, config){

    console.log(data);
    $scope.steamGames = JSON.parse($scope.rawData);
    $scope.steamSearch = document.getElementById('Search').value;

  });

编辑:为了清楚起见,我还检查了 JSON 验证器,它发出的 JSON 是有效的。

我们有答案。 Steam 的 API 不允许您使用 CORS 向它发送请求(因为它不允许跨源请求)。如果您通过 JSONP 发送它,那么您会像我一样收到意外的令牌错误。不过,还是有希望的。

使用 CodePen 上的教程,我能够向 Steam Web 发出请求 API(使用我用 NodeJS 编写的服务器)并从变量中的响应中捕获 JSON。我的下一步行动是以某种方式将该变量发送到 Angular JS,并使用我的 HTML 中的 ng-repeat 指令从中获取正确的值。谢谢大家的帮助。

编辑:这是 CodePen 教程的 link 以及所需的 nodeJS/ExpressJS 代码: https://codepen.io/johnchristopherjones/post/how-do-i-use-the-steam-api-in-my-web-app

app.get('/steam/civ5achievements', function(httpRequest, httpResponse) {
    // Calculate the Steam API URL we want to use
    var url = 'http://api.steampowered.com/ISteamUserStats/GetSchemaForGame/' +
        'v2/?key=YOURSTEAMAPIKEYHERE&appid=8930';
    request.get(url, function(error, steamHttpResponse, steamHttpBody) {
        // Once we get the body of the steamHttpResponse, send it to our client
        // as our own httpResponse
        httpResponse.setHeader('Content-Type', 'application/json');
        httpResponse.send(steamHttpBody);
    });
});