我已经开发了自己的C#应用程序来调用twitch api来获取我当前关注的所有实时用户的列表。它一直运行得很好,直到四月份之类的时候。
我通过WebClient.DownloadString将此字符串传递给代码中的调用,以便使用json进行解析:
https://api.twitch.tv/kraken/streams/followed?oauth_token=[mytoken]&stream_type=live
这以前工作得很好,从web返回了一个很长的可解析字符串,我在我的应用程序中使用了它。
但是现在返回的字符串表明我缺少作用域(我的oauth是正确的)。
因此,我继续在web浏览器上尝试,通过以下链接检查我的oauth是否正确:[https://api.twitch.tv/kraken?oauth_token=[my](https://api.twitch.tv/kraken?oauth_token=[my) oauth]
这将返回一个有效的字符串,但事实证明,我从web获得的令牌只有chat_login作用域。我想设置一个user_read作用域,或者至少检索一个具有user_read作用域的令牌。不是chat_login作用域;因为chat_login作用域不允许我通过https//api.twitch.tv/kraken/streams/followed?oauth_token=mytoken&stream_type=live获取字符串
在github中twitch api的认证手册中,有一个进程需要一个调用,该调用允许我的应用程序访问我的twitch信息。我需要在那里指定redirect_uri来获取具有user_read作用域的access_token。
但是我不知道如何指定一个redirect_uri,以及调用哪个函数来返回带有我需要的user_read作用域的access_token字符串。
这是v3 twitch api中的新功能吗?(哪一项可能在4月份左右发生变化?)
总而言之:我应该怎么做才能得到一个具有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);
}提前感谢您的宝贵时间。
发布于 2016-06-15 16:47:05
我不确定这是否正确,但我认为您用于api调用的URL已更改
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
我想他们把它从流媒体改成了频道
如果这不起作用,很抱歉
https://stackoverflow.com/questions/37727422
复制相似问题