简体   繁体   English

带有Angularjs的JSONP不适用于TwitchTV API

[英]JSONP with Angularjs doesn't work with TwitchTV api

I've been trying to build a little app with Angular and the TwitchTV api but I'm having a lot of trouble with JSONP. 我一直在尝试使用Angular和TwitchTV api构建一个小应用程序,但是在JSONP方面遇到很多麻烦。 It seems like I can pull in the data just fine, but crawling through Object nets me a white screen of nothing. 看起来我可以很好地提取数据,但是通过Object进行爬网却使我一无所有。 I get no errors either so debugging has been impossible. 我也没有收到任何错误,因此调试是不可能的。 Here is my current set up. 这是我当前的设置。

SERVICE 服务

  .factory('twitchTEST', function($resource){
    var resource = $resource('https://api.twitch.tv/kraken/channels/nl_kripp/videos',{},{
      query:{
        method:'JSONP',
        params: {callback: 'JSON_CALLBACK'},
        isArray:false,
        headers:{
          'Access-Control-Allow-Origin': '*',
          'Accept': 'application/vnd.twitchtv.v2+json',
          'Client-ID': 'fcn1buiw3t57k9yduoqvwxdk3awb2rf'
        }
      },
    });
    return resource;
  });

CONTROLER 控制器

  .controller('MainCtrl', function($scope, twitchTEST) {
    twitchTEST.query(function(data){
      $scope.twitches = data;
    });
  });

HTML 的HTML

<div ng-repeat="twitch in twitches">
  <span>{{ twitch.name }}</span>
</div>

With this set up I get just a white screen. 通过此设置,我只会得到一个白色的屏幕。 The odd part is that if I change the template to just : 奇怪的是,如果我将模板更改为just:

<div ng-repeat="twitch in twitches">
  <span>{{ twitch}}</span>
</div>

I then will get the entire object. 然后,我将获得整个对象。 For some reason I dont know how to just get a name, status, or any other field. 由于某些原因,我不知道如何获取名称,状态或任何其他字段。 I'm really not sure what I'm doing wrong at this point. 我真的不确定目前在做什么错。 A bit lost. 有点失落。

I'm a moron. 我是白痴。 I just realized there is nothing in the OBJECT to repeat on... So sorry for the time wasting guys. 我只是意识到对象中没有什么可以重复的了...非常抱歉浪费时间。 Maybe this will help someone else out there who is up way to late for their own good. 也许这将帮助其他为自己的利益而迟到的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM