I’m trying to pick up AngularJS by making a simple Twitch web app but I am having troubles working around cross origin resource sharing. I read that the Twitch API methods support JSONP so I’m assuming that any requests I make, such as getting user root info(https://github.com/justintv/Twitch-API/blob/master/v3_resources/root.md) should be done using the angularjs $http service, right? If that is right, how do I set headers for such a request?
Can anyone provide an example of requesting user root info using angularJS? This is what I have tried inside my custom ‘twitchService’ that I made:
angular.module('streamPlaylisterAppServices', []).factory('twitchService', ['$http',
function($http) {
return function(usercode){
console.log("usercode inside service is: " + usercode)
var authHeader = 'OAuth' + usercode;
$http.defaults.headers.common.Authorization = 'Authorization: OAuth ' + usercode
$http.defaults.headers.common.Accept = 'Accept: application/vnd.twitchtv.v3+json'
return $http.jsonp('https://api.twitch.tv/kraken?callback=JSON_CALLBACK').success(function (data){
console.log("success jsonp request. Response: " + JSON.stringify(data));
}) // end success
.error(function (data){
console.log("http root request failed.");
});// end error
};
}]);