I am preparing a windows application in that I want to use oAuth2 to access info from google plus.
But I am getting bad request for my following code.. I am able to create app in google console and fetch the "code" for application access.
WebRequest request = WebRequest.Create(
GoogleAuthenticationServer.Description.TokenEndpoint
);
// You must use POST for the code exchange.
request.Method = "POST";
// Create POST data.
string postData = FormPostData(code);
byte[] byteArray = Encoding.UTF8.`enter code here`GetBytes(postData);
// Set up the POST request for the code exchange.
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
// Perform the POST and retrieve the server response with
// the access token and/or the refresh token.
WebResponse response = request.GetResponse();
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
reader.Close();
dataStream.Close();
response.Close();
// Convert the response JSON to an object and return it.
return JsonConvert.DeserializeObject<OAuthResponseObject>(
responseFromServer);
Now, I am trying to use that code to get the access token. .which is giving me BAD request.
I also followed few post on stackoverflow. but none of them working for me.
Thanks
EDIT:
Thanks for the reply. I was able to do it my own somehow :)
I was able to do it my own using following code..
I am assuming to have two button on window.. button1 is used to get CODE from google and button2 uses that code and get the access_token which is what I was looking for.
i think you can begin this way :
Google plus OAuth
For web applications, I would strongly recommend you use a one-time-code flow as demonstrated in the Google+ Quickstart sample. Please try working through the Quickstart instructions to make sure you're not missing any steps. When you do Google+ Sign-In this way, you will be able to get over-the-air installs of Android apps (if you have one for your site) and will be applying best practices for authorization.
All of the code for doing this is available in the sample which also demonstrates integration with the Google client libraries - this opens up access to all of the Google APIs and product integrations.
From Windows apps or installed apps, you would need to do more of the heavy lifting yourself. The following blog article covers how you could do the authorization in legacy scenarios:
http://gusclass.com/blog/2012/08/31/using-the-google-net-client-library-with-google/
There is an example as well:
http://gusclass.com/projects/PlusDotNet.zip
A couple notes: