【发布时间】:2016-10-10 04:37:40
【问题描述】:
我开发了自己的 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=[myoauth]
这会返回一个有效的字符串但是; 事实证明,我从 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 中的新功能吗? (可能在四月份左右发生变化?)
总结一下:我应该怎么做才能获得一个具有 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);
}
提前感谢您的宝贵时间。
【问题讨论】:
-
随着我对该主题的深入研究,我得出一个结论,即我需要一个 webview 对象来从其 URL 获取 access_token。但我不知道该怎么做或我应该将此字符串传递给哪个函数: https api.twitch.tv/kraken/oauth2/authorize ?response_type=token &client_id=
&redirect_uri="localhost(???)" &scope=user_read