我目前正在使用twitch api使用C#和Windows Forms编写机器人。 为了能够访问当前用户的流标题,游戏和其他信息,我必须让用户抽搐以便用户可以登录并授予我的应用访问权限。 这个网址看起来像这样:
System.Diagnostics.Process.Start("https://api.twitch.tv/kraken/oauth2/authorize?response_type=token&client_id=" + client_id + "&redirect_uri=http://localhost&scope=channel_read+channel_editor+channel_commercial+channel_subscriptions+channel_check_subscription当用户输入他们的信息并按下授权时,它会将它们发送到我提供的链接(本地主机),并将访问令牌附加到网址上。 这看起来像这样:
http://localhost/#access_token=[access token]&scope=channel_read+channel_editor+channel_commercial+channel_subscriptions+channel_check_subscription题
打开该链接的最佳方式是什么?等待用户输入他们的信息,然后从他们获得的下一个URL获取访问令牌? 这不是使用ASP,这是一个同步调用。 我对缺少代码表示歉意,我已经尝试了多种方式,而且我似乎找不到任何即使接近工作的东西。
I am currently using the twitch api to write a bot using C# and Windows Forms. In order to get access to the current user's stream title, game, and other information, I have to send the user to twitch so that the user can log in and give my app access. This url looks something like this:
System.Diagnostics.Process.Start("https://api.twitch.tv/kraken/oauth2/authorize?response_type=token&client_id=" + client_id + "&redirect_uri=http://localhost&scope=channel_read+channel_editor+channel_commercial+channel_subscriptions+channel_check_subscriptionWhen the user enters their information in and presses authorize, it sends them to a link that I provided (localhost) and appends an access token onto the url. This looks something like this:
http://localhost/#access_token=[access token]&scope=channel_read+channel_editor+channel_commercial+channel_subscriptions+channel_check_subscriptionQuestion
What is the best way to open that link, wait for the user to enter in their information, and then get the access token from the next url that they get to? This is not using ASP and this is a synchronous call. I apologize for the lack of code, I have tried multiple things and I cant seem to find anything that even comes close to working.
最满意答案
所以经过了一整天的讨论后,我找到了一种方法,可以从Yorye Nathan那里获得网址。
为了解决我的问题,我打开了一个windows窗体(具有客户端ID的URL从主窗体传递)的twitch身份验证页面:
public WebAuthentication(string url) { InitializeComponent(); webBrowser1.Navigate(url); }然后,我使用DocumentCompleted事件处理程序来检查浏览器是否加载了本地主机页面。 如果本地主机页面已被加载,则该方法保存该URL,然后关闭该表单:
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { if (webBrowser1.Url.ToString().StartsWith("http://localhost") || webBrowser1.Url.ToString().StartsWith("https://localhost")) { mainForm.SetUserToken(webBrowser1.Url.ToString()); this.Hide(); } }So after a day of messing around with it, I have found a way to get the url with the tip from Yorye Nathan.
To solve my issue, I opened the twitch authentication page with a windows form (the url with client id is passed from the main form):
public WebAuthentication(string url) { InitializeComponent(); webBrowser1.Navigate(url); }I then used a DocumentCompleted event handler to check to see if the browser has loaded the local host page. If the local host page has been loaded, the method saves the URL and then closes the form.:
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { if (webBrowser1.Url.ToString().StartsWith("http://localhost") || webBrowser1.Url.ToString().StartsWith("https://localhost")) { mainForm.SetUserToken(webBrowser1.Url.ToString()); this.Hide(); } }更多推荐
发布评论