-
Notifications
You must be signed in to change notification settings - Fork 2
Front End Project Use Twitchtv JSON API
If you're trying to tackle this challenge with jQuery's $.getJSON()
method, chances are you'll get an error message concerning Cross-Origin Resource Sharing (CORS).
The easiest way to resolve this is to use jQuery's JSONP capabilities. From the Twitch API's readme page:
All API methods support JSON-P by providing a callback parameter with the request.
Also the jQuery documentation states:
If the URL includes the string "callback=?" (or similar, as defined by the server-side API), the request is treated as JSONP instead.
Here's an example call to fetch Free Code Camp's Twitch channel data:
$.getJSON('https://api.twitch.tv/kraken/streams/freecodecamp?callback=?', function(data) {
console.log(data);
});
JSONP is considered insecure according to Wikipedia, but should be sufficient for our purposes. For a detailed discussion on Twitch's CORS restriction, please read issue #133 on the Twitch-API repository.
Learn to code and help nonprofits. Join our open source community in 15 seconds at http://freecodecamp.com
Follow our Medium blog
Follow Quincy on Quora
Follow us on Twitter
Like us on Facebook
And be sure to click the "Star" button in the upper right of this page.
New to Free Code Camp?
JS Concepts
JS Language Reference
- arguments
- Array.prototype.filter
- Array.prototype.indexOf
- Array.prototype.map
- Array.prototype.pop
- Array.prototype.push
- Array.prototype.shift
- Array.prototype.slice
- Array.prototype.some
- Array.prototype.toString
- Boolean
- for loop
- for..in loop
- for..of loop
- String.prototype.split
- String.prototype.toLowerCase
- String.prototype.toUpperCase
- undefined
Other Links