来自C#流的Twitch API调用/关注

时间:2016-06-09 13:29:53

标签: c# api oauth twitch

我开发了自己的C#应用​​程序来调用twitch api以获取我当前关注的所有实时用户的列表。它工作正常,直到四月或其他什么。

我通过WebClient.DownloadString将此字符串传递给代码中的调用,以便用json解析:

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

这曾经工作正常,并从我在我的应用程序中使用的web返回了一个长的可解析字符串。

但现在返回的字符串表示我错过了范围。(我的oauth是正确的)

所以我继续在网络浏览器上尝试这个,通过以下链接检查我的oauth是否正确:https://api.twitch.tv/kraken?oauth_token=[my oauth]

这会返回一个有效的字符串但是; 事实证明,我从网上获得的令牌只有chat_login范围。我想设置user_read范围或至少检索具有user_read范围的令牌。不是chat_login范围;由于chat_login范围不允许我通过https // api.twitch.tv / kraken / streams / follow获取字符串?oauth_token = [mytoken]& stream_type = live

在github中twitch api的身份验证手册中,有一个过程需要一个允许我的应用程序访问我的抽搐信息的调用。我需要在那里指定redirect_uri来获取具有user_read范围的access_token。

但我不知道如何指定redirect_uri以及调用哪个函数将返回带有我需要的user_read范围的access_token字符串。

这是v3 twitch api的新功能吗? (四月份可能会改变一下?)

总结一下:如何获得具有user_read范围而不是chat_login范围的#access_token?

我的代码:

    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);   
    }

提前感谢您的时间。

1 个答案:

答案 0 :(得分:0)

我不确定这是否正确,但我认为用于api通话的网址已经改变

HTTPS // api.twitch.tv /海怪/流/随后组oauth_token = [即为MyToken]&安培;?的stream_type =活

HTTPS // api.twitch.tv /海怪/信道/随后组oauth_token = [即为MyToken]&安培;?的stream_type =活

我认为他们将其从流改为频道

很抱歉,如果这无济于事