等待用户填写API登录,获取下一页的URL
Wait for user to fill in API login and get URL of the next page
我目前正在使用 twitch api 编写一个使用 C# 和 Windows 表单的机器人。为了访问当前用户的流标题、游戏和其他信息,我必须将用户发送到 twitch,以便用户可以登录并授予我的应用程序访问权限。这个 url 看起来像这样:
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
当用户输入他们的信息并按下授权时,它会将他们发送到我提供的 link(本地主机)并将访问令牌附加到 url。这看起来像这样:
http://localhost/#access_token=[access token]&scope=channel_read+channel_editor+channel_commercial+channel_subscriptions+channel_check_subscription
问题
打开 link 的最佳方法是什么,等待用户输入他们的信息,然后从他们到达的下一个 url 获取访问令牌?这没有使用 ASP,这是一个同步调用。对于缺少代码,我深表歉意,我尝试了多种方法,但似乎找不到任何接近工作的方法。
所以在折腾了一天之后,我找到了一种方法,可以通过 Yorye Nathan 的小费获得 url。
为了解决我的问题,我打开了带有 windows 表单的 twitch 身份验证页面(带有客户端 ID 的 url 从主表单传递):
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();
}
}
我目前正在使用 twitch api 编写一个使用 C# 和 Windows 表单的机器人。为了访问当前用户的流标题、游戏和其他信息,我必须将用户发送到 twitch,以便用户可以登录并授予我的应用程序访问权限。这个 url 看起来像这样:
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
当用户输入他们的信息并按下授权时,它会将他们发送到我提供的 link(本地主机)并将访问令牌附加到 url。这看起来像这样:
http://localhost/#access_token=[access token]&scope=channel_read+channel_editor+channel_commercial+channel_subscriptions+channel_check_subscription
问题
打开 link 的最佳方法是什么,等待用户输入他们的信息,然后从他们到达的下一个 url 获取访问令牌?这没有使用 ASP,这是一个同步调用。对于缺少代码,我深表歉意,我尝试了多种方法,但似乎找不到任何接近工作的方法。
所以在折腾了一天之后,我找到了一种方法,可以通过 Yorye Nathan 的小费获得 url。
为了解决我的问题,我打开了带有 windows 表单的 twitch 身份验证页面(带有客户端 ID 的 url 从主表单传递):
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();
}
}