ssett / google-api-dotnet-client

Automatically exported from code.google.com/p/google-api-dotnet-client
Apache License 2.0
0 stars 0 forks source link

I am doing OAuth 2.0 Authentcation with Rest Method but it is throwing error though i have given proper inputs for that #512

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.  HttpWebRequest request = WebRequest.Create(@"
                                                       https://accounts.google.com/o/oauth2/auth?client_id=764757459177-8hmhrjfp241p9e3nih02jko0ufevhjk5.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%2FWebApplication1/Contact.aspx&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fyoutube&response_type=code&access_type=offline&pageId=none") as HttpWebRequest;
            request.Method = "POST";
            request.ContentType = "text/xml";
            request.ContentLength = 0;
            using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
            {

                Response.Redirect(response.ResponseUri.ToString());
                // Get the response stream 
              //  StreamReader reader = new StreamReader(response.GetResponseStream());

                // Console application output 
              //  string strOutputXml = reader.ReadToEnd();
            } 

this post request will give authorization code then i am going to exchange it 
for token as mentioned in step 2
2. string code = Request.QueryString["code"];

            HttpWebRequest request = WebRequest.Create(@"https://accounts.google.com/o/oauth2/token") as HttpWebRequest;

            request.ContentType = "application/x-www-form-urlencoded";
            request.Host = "accounts.google.com";
            request.Method = "POST";

            string postData = @"code=" + (code) + @"&client_id=711646569701764757459177-8hmhrjfp241p9e3nih02jko0ufevhjk5.apps.googleusercontent.com&client_secret=WMDM2kTtkaLq4W4_JVUKWf6A&redirect_uri=http://localhost/WebApplication1/Contact.aspx" + "&grant_type=authorization_code";
            byte[] byteArray = Encoding.UTF8.GetBytes (postData);
            // Set the ContentType property of the WebRequest.

            // Set the ContentLength property of the WebRequest.
            request.ContentLength = byteArray.Length;
            // Get the request stream.
            Stream dataStream = request.GetRequestStream ();
            // Write the data to the request stream.
            dataStream.Write (byteArray, 0, byteArray.Length);
            // Close the Stream object.
           // dataStream.Close ();

            using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
            {

              //  Response.Redirect(response.ResponseUri.ToString());
                // Get the response stream 
                //  StreamReader reader = new StreamReader(response.GetResponseStream());

                // Console application output 
                //  string strOutputXml = reader.ReadToEnd();
            }

        }

What is the expected output? What do you see instead?
this  should return json file with acess token and refresh token but it is 
displayinh unauthorized access 401 with c# code.
but when doing same request using fiddle agent .it is displaying
error: missing grant type

What version of the product are you using? Youtube Data API 3.0
What is your operating system? windows 7
What is your IDE?VS2012
What is the .NET framework version?4.5

Please provide any additional information below.
my credetials are as per below:
 string devkey = "AI39si6K0w-_I596d4zS7laheBgl5IWDqLKb3v8cuBfRkNTNKw- NcJ69iu2rG8xnjxRvXf6kkfCOLB81V2kt_Dt8Ywigx_vr3w";
        public string username = "hb.dev002";
        string password = "hb123456";

        public string channelId = "UCyAn2aVZWNAugdlckOJKG5A";

Original issue reported on code.google.com by hbms....@gmail.com on 26 Nov 2014 at 12:43

GoogleCodeExporter commented 9 years ago
You're not using the .NET client library. You should follow our instructions in 
developers.google.com/api-client-library/dotnet/. I'm closing this issue for 
now, because it's not related to the .NET client library for Google APIs.

Original comment by pele...@google.com on 10 Dec 2014 at 4:15