내 웹 사이트의 트위 뷰 TV 계정을 사용자 프로필에 연결하려고하는데 403 Forbidden 오류가 발생합니다. 여기에 지정된 인증 코드 플로를 사용하려고합니다 : https://github.com/justintv/Twitch-API/blob/master/authentication.md#auth-code하지만 Twitch TV에 다시 게시해야하는 곳의 두 번째 부분에서 오류가 발생합니다. ASP.net MVC3 및 C#을 사용하여이 작업을 수행하고 있습니다. 여기 Twitch TV OAuth 로그인 C#
코드를 얻을 TV를 트 내 응용 프로그램에 액세스 할 수 있도록 사용자에게 내 방법 (이 예상대로 작동)입니다 :[Authorize]
public ActionResult TwitchTvLogOn(string returnUrl)
{
string redirectUrl = "";
// This is special code used to determine the URL that will be used when working in UGDB since the URL is different in
// development than it is in production.
#if (DEBUG)
redirectUrl = "http://localhost:58386/Account/AuthorizeTwitchTv";
#else
redirectUrl = "http://www.mywebsite.com/Account/AuthorizeTwitchTv";
#endif
var loginUri = "https://api.twitch.tv/kraken/oauth2/authorize?response_type=code&client_id=" +
System.Configuration.ConfigurationManager.AppSettings["TwitchClientId"] +
"&redirect_uri=" + redirectUrl + "&state=" + returnUrl;
return Redirect(loginUri);
}
이 제대로 작동하지 않는 부분이고주고있다 403 :
public ActionResult AuthorizeTwitchTv(string code, string state)
{
string currentUrl = Request.Url.AbsoluteUri;
string redirectUrl = "";
#if (DEBUG)
redirectUrl = "http://localhost:58386/Account/AuthorizeTwitchTv";
#else
redirectUrl = "http://www.mywebsite.com/Account/AuthorizeTwitchTv";
#endif
var twitchTvPost = "https://api.twitch.tv/kraken/oauth2/token?client_id=" +
System.Configuration.ConfigurationManager.AppSettings["TwitchClientId"] + "&client_secret=" +
System.Configuration.ConfigurationManager.AppSettings["TwitchAppSecret"] + "&grant_type=authorization_code&redirect_uri=" +
redirectUrl + "&code=" + code;
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "client_id=" + System.Configuration.ConfigurationManager.AppSettings["TwitchClientId"];
postData += ("&client_secret=" + System.Configuration.ConfigurationManager.AppSettings["TwitchAppSecret"]);
postData += ("&grant_type=authorization_code");
postData += ("&redirect_uri=" + redirectUrl);
postData += ("&code=" + code);
byte[] data = encoding.GetBytes(postData);
// Prepare POST web request...
HttpWebRequest myRequest =
(HttpWebRequest)WebRequest.Create(new Uri("https://api.twitch.tv/kraken/oauth2/token"));
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
Stream newStream = myRequest.GetRequestStream();
// Send the data.
newStream.Write(data, 0, data.Length);
newStream.Close();
// Get response
HttpWebResponse response = (HttpWebResponse)myRequest.GetResponse();
// Get the response stream
StreamReader reader = new StreamReader(response.GetResponseStream());
// Read the whole contents and return as a string
string result = reader.ReadToEnd();
return View();
}
어떤 도움을 주시면 대단히 감사하겠습니다. 전반적인 최종 목표는 "access_token"을 얻는 것이므로 현재 사용자의 트 위치 사용자 이름을 얻고 해당 사용자의 채널과 피드를 가져올 수 있습니다.
실은 그것을 염두에두고 작동하도록 만들면 어떤 의미가 있습니다. 감사! –
그 점을 염두에두고 내 코드를 살펴보면 나는 몇 곳에서 여분의 신호를 보았고 내 비밀과 ID는 localhost보다는 생산을위한 것이라는 것을 알았습니다. –