Unable to Authorize with own ajax code

Hi everyone, new member here on the forum!

I’m working on a small test with the API, but can’t make it work properly by using my on AJAX code authorize. The piece below:

var base_url = "https://api.twitch.tv/kraken/";

var params = {
    response_type: 'token',
    
    client_id: [My client Id],
    redirect_uri: 'http://localhost',
    scope: 'user_read'
};

var url = base_url +"oauth2/authorize?" + $.param(params);    

$.ajax({
        url: url,
        dataType: 'jsonp',
        type: 'post',
        contentType: 'application/vnd.twitchtv.v2+json'
    })
    .done(function (msg){
        log( "Data: "+JSON.stringify(msg));
    })
    .fail(function (msg ){
        log( "Error: "+JSON.stringify(msg));
    });

Returns this on Chrome:

Uncaught SyntaxError: Unexpected token <

on

authenticate?_=1418417804931&action=authorize&callback=jQuery111104965348285622895_1418417804930&cl…:1 

And my callback gives me:

[LOG] Error: {"readyState":4,"status":200,"statusText":"success"}

Using the SDK does not render the same problem, in fact I’m able to redirect the page to the login section. However, my app will not run on a browser, so I would like to use my own custom user interface. Still, even making my code as similar as possible with the API, it didn’t work.

Does anyone had a similar experience? :smile:

Best Regards!

Adriel

oauth2/authorize is not a URL that will return JSON or JSONP data. It is a page that you will redirect users to accept your app authorization.

See https://github.com/justintv/Twitch-API/blob/master/authentication.md for details on implementing the various types of auth flows.

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