0
votes

I had developed my own C# application to make calls to twitch api to get list of all the live users i am currently following. It was working fine until April or something.

I pass this string to the call in the code via WebClient.DownloadString to be parsed with json:

https://api.twitch.tv/kraken/streams/followed?oauth_token=[mytoken]&stream_type=live

This used to work fine and returned a long parsable string from web which i used in my app.

But now the string returned says that i am missing the scope.(my oauth is correct)

So i went on and tried this on a web browser to check if my oauth is correct via this link: https://api.twitch.tv/kraken?oauth_token=[my oauth]

This returns a valid string but; It turns out that the token i got from web has only chat_login scope. I want to set a user_read scope or at least retrieve a token which has user_read scope. Not chat_login scope; as chat_login scope does not permit me getting string via https//api.twitch.tv/kraken/streams/followed?oauth_token=[mytoken]&stream_type=live

In the authentication manual of twitch api in github there is a process which requires a call that grants my application access to my twitch info. I need to specify redirect_uri there to get the access_token which has the user_read scope.

But i have no idea about how to specify a redirect_uri and which function to call that will return the access_token string with the user_read scope that i need.

Is this new in v3 twitch api? (Which is probably changed around in April?)

To summarize: What should i do to get an #access_token which has a user_read scope rather than chat_login scope?

My Code:

    public partial class Form1 : Form
{
    const string chName = "ryetta";
    const string FollowsURL = "https://api.twitch.tv/kraken/users/" + chName + "/follows/channels?limit=200&sortby=last_broadcast";
    const string oauth = "4yk...";
    const string FollowedURL = "https://api.twitch.tv/kraken/streams/followed?oauth_token=" + oauth + "&stream_type=live";

    BindingList<ChannelData> channels = new BindingList<ChannelData>();
    WebClient wc;
    string selectedChannelName;

    public Form1()
    {
        InitializeComponent();

        wc = new WebClient();

    }

    private void button1_Click(object sender, EventArgs e)
    {
        string s = jsonget(FollowedURL); // this is where i get the scope error so the other parts of the code is irrelevant
        //JObject jObj = JObject.Parse(s);

        StreamFollowed streams1 = JsonConvert.DeserializeObject<StreamFollowed>(s);
        channels.Clear();
        foreach (Stream stream in streams1.streams)
        {
            System.IO.Stream str = wc.OpenRead(stream.preview.medium);
            Bitmap bmp = new Bitmap(str);
            channels.Add(new ChannelData(stream, bmp));


        }

        dataGridView1.DataSource = channels.Select(cdata => new {
            cdata.Name,
            cdata.ViewerCount,
            cdata.Game,
            cdata.Title,
            cdata.UpTimeString,
            cdata.BmpPreview,
            cdata.followersCount,
            cdata.ratio}).ToList();

        selectedChannelName = (string)dataGridView1.SelectedRows[0].Cells[0].Value;


    }
        public string jsonget(string url)
    {
        return wc.DownloadString(url);   
    }

Thanks in advance for your time.

1
As i research more into the subject i come into a conclusion that i need a webview object to get the access_token from its URL. But i have no idea how to do it or which function i should pass this string to: https api.twitch.tv/kraken/oauth2/authorize ?response_type=token &client_id=<client_id> &redirect_uri="localhost(???)" &scope=user_read - bcbeyhan

1 Answers

0
votes

I'm not sure if this is correct or not but the URL you use for the api call I think has changed

https//api.twitch.tv/kraken/streams/followed?oauth_token=[mytoken]&stream_type=live

https//api.twitch.tv/kraken/channels/followed?oauth_token=[mytoken]&stream_type=live

I think they changed it from streams to channels

Sorry if this doesn't help though