justintv / Twitch-API

A home for details about our API
www.twitch.tv
1.72k stars 380 forks source link

Getting Bad request on authenticate #484

Closed innoszorn83 closed 8 years ago

innoszorn83 commented 8 years ago

Hello I am trying to get an oauth2 authentication on twitch.tv with asmall c# program. i am using the https://github.com/justintv/Twitch-API/blob/master/authentication.md#authenticated-requests. Here is the part of my c# code who doesn't work:

             var loginURL = "https://api.twitch.tv/kraken/oauth2/authorize?
                                       response_type=code&"+
                                       client_id=jlilx7k22i8ak99aaloqy9i92qk353m"+
                                      "&redirect_uri=http://localhost&"+
                                       "state=TWStreamingStateAuthenticated";                    
            this.richTextBox1.Text = loginURL;
            string code = get_DownLoadString(loginURL);
            this.richTextBox1.Text = code;
            WebRequest request = WebRequest.Create("https://api.twitch.tv/kraken/oauth2/token");
            request.Method = "POST";
            string postData = "client_id=jlilx7k22i8ak99aaloqy9i92qk353m" +
                              "&client_secret=...." +
                              "&grant_type=authorization_code" +
                              "&redirect_uri=http://localhost" +
                              "&code=" + code +
                              "&state=TWStreamingStateAuthenticated";

            ASCIIEncoding encoding = new ASCIIEncoding();
            postData = HttpUtility.UrlEncode(postData);            
            byte[] byteArray = encoding.GetBytes(postData);
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = byteArray.Length;
            Stream datatream = request.GetRequestStream();
            datatream.Write(byteArray, 0, byteArray.Length);
            datatream.Close();
            WebResponse respone = request.GetResponse();
            MessageBox.Show(((HttpWebResponse)respone).StatusDescription);

I get the 400 Error: Bad Request. I try this since days and i cant find any solution. Can anybody help me?

DallasNChains commented 8 years ago

You should ask general questions like this on the Twitch Developer Forums.