# Getting strated with Twitch api

**URL:** <https://discuss.dev.twitch.com/t/getting-strated-with-twitch-api/2064>\
**Category:** API\
**Created:** [April 19, 2015, 1:18pm UTC](https://discuss.dev.twitch.com/t/getting-strated-with-twitch-api/2064 "2015-04-19T13:18:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gertulio](https://avatars.discourse-cdn.com/v4/letter/g/41988e/32.png) [@Gertulio](https://discuss.dev.twitch.com/u/Gertulio)\
**Post date:** [April 19, 2015, 1:18pm UTC](https://discuss.dev.twitch.com/t/getting-strated-with-twitch-api/2064/1 "2015-04-19T13:18:07Z")

</div>

Hi. I’m having problems getting data from the twitch api. I’m building an app that allows to get data about Twitch channels and games through a search engine. However I keep getting and error saying :

“XMLHttpRequest cannot load [https://api.twitch.tv/kraken/channels/lirik](https://api.twitch.tv/kraken/channels/lirik). No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘file://’ is therefore not allowed access.”

For now I’m just trying to get the information to the console.

Here’s what I have to inititialize the APi

```
    <script src="jquery-2.1.3.min.js"></script>
    <script src="https://ttv-api.s3.amazonaws.com/twitch.min.js"></script>
    <script>
        Twitch.init({clientId: '4lqupncds31igxdrqek4ln6m2lnuykk'}, function(error, status) {
            
    // the sdk is now loaded
        });$('.twitch-connect').click(function() {
            Twitch.login({
                scope: ['user_read', 'channel_read']
            });
        })

    </script>

```

Here’s the code that allows me to search:

```
//API docs: http://www.omdbapi.com
var base_url = "https://api.twitch.tv/kraken/channels/";
var index;
//array de filmes, não inicializado
var channels = [];

$(function() {

    $("#load").hide();
    $("#next, #previous").attr('disabled',true);

    $("#next").click(proximo);
    $("#previous").click(anterior);
    
    $("#search").click(procura);
});

function procura(){
    
    procurando();
    buscaFilmes();
}

function buscaFilmes(){

    var texto = $("#text").val();
    //var tipo = $("#type").val();
    //var ano = $("#year").val();
    
    var replaced = texto.split(' ').join('+');
    
    if(texto.length > 0){
        
        log("Procurar por filmes com '"+texto+"...");
        //1 pesquisa por filmes de acordo com texto, tipo e, se preenchido, com ano -- deve usar getJSON
        $.getJSON(base_url + texto, function(json) {

               //TMDb is nice enough to return a message if nothing was found, so we can base our if statement on this information

               if (json != "Nothing found."){

                  //Display the poster and a message announcing the result

                     $('#results').html('<h2 class="loading">Well, gee whiz! We found you a poster, skip!</h2><img id="thePoster" src=' + json[0].channels[0] + ' />');
                    
       
    } else {
        alert("Preencha o campo textual!");
    }
            });}
}

```

I keep searching channels names, for example: “[https://api.twitch.tv/kraken/channels/lirik](https://api.twitch.tv/kraken/channels/lirik)”, and i get the error described above.

Can someone help me. I dont know what I’m doing wrong…

---

<div class="post-metadata">

**Author:** ![Fugiman](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/fugiman/32/108_2.png) [@Fugiman](https://discuss.dev.twitch.com/u/Fugiman)\
**Post date:** [April 19, 2015, 1:56pm UTC](https://discuss.dev.twitch.com/t/getting-strated-with-twitch-api/2064/2 "2015-04-19T13:56:57Z")

</div>

Twitch’s API does not support [CORS](http://www.html5rocks.com/en/tutorials/cors/), you’ll need to use [JSONP](http://bob.ippoli.to/archives/2005/12/05/remote-json-jsonp/). You can use `Twitch.api` provided by the JS SDK that you seem to already be using, or keep using jQuery but set `dataType: "jsonp"`.

---

<div class="post-metadata">

**Author:** ![Gertulio](https://avatars.discourse-cdn.com/v4/letter/g/41988e/32.png) [@Gertulio](https://discuss.dev.twitch.com/u/Gertulio)\
**Post date:** [April 19, 2015, 3:32pm UTC](https://discuss.dev.twitch.com/t/getting-strated-with-twitch-api/2064/3 "2015-04-19T15:32:45Z")

</div>

Yes . That was ir. Thank you 🙂

---

<div class="post-metadata">

**Author:** ![system](https://d2opxh93rbxzdn.cloudfront.net/original/2X/0/05909729875cce3b53e59d5561c4d23bb14948fc.png) [@system](https://discuss.dev.twitch.com/u/system)\
**Post date:** [May 19, 2015, 3:33pm UTC](https://discuss.dev.twitch.com/t/getting-strated-with-twitch-api/2064/4 "2015-05-19T15:33:00Z")

</div>

Closed on May 19, 2015, 3:33pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
