[Resolved]Getting subscribers list with ajax (jquery)

Hi guys, I’m trying to get subscription list of my channel and I’m new in all of this.
I’ve never used OAuth before and the only thing that I need is how to be authenticated just for get my subscribers list. I’m not using any kind of server, I only want to receive this data as a JSON.
I have an HTML local file and the following code in a “script” tag:

$.ajax({
 type: 'POST',
 url: 'https://api.twitch.tv/kraken/channels/mychannel/subscriptions',
 headers: {
   'Authorization': 'OAuth MY-CLIENT-SECRET',
   'Client-ID': 'MY-CLIENT-ID'
 },
 success: function(data) {
   console.log(data);
 }
});

I tested with the call for get a list of followers with a similiar code and I had no problem.
I’ve read authenticantion article but I can’t get it.

Cheers!

The client secret is not the same as an oauth token, which you need to get through an authorization flow from the user whose data you’re trying to access.

Then, which is the oauth token that I need? The data that I’m requesting is from my channel.
I tried with the following

$.ajax({
 type: 'GET',
 url: 'https://api.twitch.tv/kraken/oauth2/authorize?response_type=token&client_id=MY-CLIENT-ID&redirect_uri=http://localhost&scope=channel_subscriptions&state=testest',
 headers: {
   'Client-ID': 'MY-CLIENT-ID'
 },
 success: function(data) {
   console.log(data);
 }
});

but I have the following error in Chrome console

XMLHttpRequest cannot load https://api.twitch.tv/kraken/oauth2/authorize?response_type=token&client_id=…&redirect_uri=http://localhost&scope=channel_subscriptions&state=testest. Redirect from ‘https://api.twitch.tv/kraken/oauth2/authorize?response_type=token&client_id=…&redirect_uri=http://localhost&scope=channel_subscriptions&state=testest’ to ‘https://api.twitch.tv/kraken/oauth2/authenticate?action=authorize&client_id…%2Flocalhost&response_type=token&scope=channel_subscriptions&state=testest’ has been blocked by CORS policy: Request requires preflight, which is disallowed to follow cross-origin redirect.

I don’t want to instance a server for this simple task :frowning:

You need to go to that URL, not use XHR with it.

1 Like

Done! Thanks for that 3ventic!

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