Hello I'm trying to use the google calendar API. I'm unable to obtain an access token.
Here is the code I'm currently using:
private string ObtainAccessToken(string code)
{
string content =
"code=" + code + "&" +
"client_id=1016429729591.apps.googleusercontent.com&"+
"client_secret={MySecret}&" +
"redirect_uri=urn:ietf:wg:oauth:2.0:oob&" +
"grant_type=authorization_code";//authorization_code";
Google.Apis.Authentication.HttpRequestFactory
factory = new Google.Apis.Authentication.HttpRequestFactory();
HttpWebRequest req = factory.Create(new Uri("https://accounts.google.com/o/oauth2/token?"+content), "POST");
byte[] data = Google.Apis.Utilities.EncodeStringToUtf8(content);
req.ContentLength = data.Length;
req.ContentType = "application/x-www-form-urlencoded";
req.GetRequestStream().Write(data, 0, data.Length);
req.GetResponse();
}
The api documentation I'm following is here: https://developers.google.com/accounts/docs/OAuth2InstalledApp
I'm constantly getting HTTP Bad Request 400 error.
I have tried the solution given in this question but it doesn't work either: Google Calendar API - Bad Request (400) Trying To Swap Code For Access Token
Can someone please point out what I'm doing wrong here?