justintv / Twitch-API

A home for details about our API
www.twitch.tv
1.72k stars 379 forks source link

after making http.get request to /streams/featured, getting JSON.parse error on the response in developer tools #205

Closed blairkenneth closed 10 years ago

blairkenneth commented 10 years ago

I have written an angularjs $http.get request as follows: $scope.getStreamList = function () { $http({ method: 'GET', url: 'https://api.twitch.tv/kraken/streams/featured', headers: {'Accept': 'application/vnd.twitchtv.v3+json'}, params: {client_id: 'MY CLIENT ID', limit: '1'} }).success(function (data, status) { $scope.streams = data; $scope.streamStatus = status; }).error(function (data, status){ $scope.streams = data; $scope.streamStatus = status; }); };

When I execute this on my page I get a 200 response back from the service. When I go into my developer tools to look at the response which should be JSON data I see an error with the following:

"SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data

If you copy the request URL and paste into a browser you see the JSON data, if I setup the same request in SOAPUI it works fine, as soon as I run through my hosting at godaddy I get the error.

I think this is an Apache issue as the data is sent over as 'gzip' content-type, my Apache version is 2.4, mod_deflate is enabled.

Can someone help me resolve this issue?

FugiTech commented 10 years ago

I'm sorry, I don't really understand the issue here. What are these "developer tools"? The chrome developer tools? What are you doing to "look at the response"? What's all this about Apache? Isn't this client side code? Why isn't the browser handling the gzip compression for you?

Perhaps your issue is attempting to use JSON on a third party site? Our API doesn't set CORS headers, so for now you need to use JSONP. I made a quick mock-up that seems to work: http://jsfiddle.net/aQt7U/