【发布时间】:2015-10-08 21:28:53
【问题描述】:
我正在努力让我的自定义聊天机器人更新我的主要频道的标题(状态)。我正在关注this 的帖子,我正在尝试从REDIRECT_URI 获取access_token。
包含重定向的 URI 是:
https://api.twitch.tv/kraken/oauth2/authorize?response_type=token&client_id=CLIENT_ID&redirect_uri=REDIRECT_URI&scope=channel_editor
我已经手动测试了我的 CLIENT_ID 和 REDIRECT_URI 设置为 http://localhost 并且我从上面的 URI 中得到了这个响应(这是我想要的):
http://localhost/#access_token=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&scope=channel_editor
我正在尝试从此 URI 获取 access_token,但我似乎无法从下面的代码中获取它。我的回答是:
https://api.twitch.tv/kraken/oauth2/authenticate?action=authorize&client_id=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&redirect_uri=http%3A%2F%2Flocalhost&response_type=token&scope=channel_editor
代码:
string clientID = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
string redirectURL = "http://localhost";
string url = string.Format("https://api.twitch.tv/kraken/oauth2/authorize?response_type=token&client_id={0}&redirect_uri={1}&scope=channel_editor",
clientID, redirectURL);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.AllowAutoRedirect = false;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string redirUrl = response.Headers["Location"];
response.Close();
// Show the redirected url
Console.WriteLine("You're being redirected to: " + redirUrl);
这是一个控制台应用程序
【问题讨论】:
标签: c# api curl restsharp twitch