ASP.NET - Infusionsoft access token - Asked By Rajiv Gogia on 12-Mar-14 07:59 AM

How to get the access/refresh token using api of infusionsoft in asp.net.

Tried with the code:

 string Url = "https://api.infusionsoft.com/token";
    string grant_type = "authorization_code";
    string data = "code={0}&client_id={1}&grant_type={2}&client_secret={3}";
    string Code = Request.QueryString["code"];

     
    try
    {
      string result = string.Empty;
      //request.ContentType = "application/x-www-form-urlencoded";
      //request.ProtocolVersion = HttpVersion.Version11;
      string param = string.Format(data, Code, Client_Id, grant_type, Client_secret);
      Url += "?" + param;
      HttpWebRequest request = HttpWebRequest.Create(Url) as HttpWebRequest;
      request.Method = "POST";
      request.ContentType = "application/x-www-form-urlencoded";
      request.ProtocolVersion = HttpVersion.Version10;
      var bs = Encoding.UTF8.GetBytes(param);
      using (Stream reqStream = request.GetRequestStream())
      {
      reqStream.Write(bs, 0, bs.Length);
      }

      using (WebResponse response = request.GetResponse())
      {
      var sr = new StreamReader(response.GetResponseStream());
      result = sr.ReadToEnd();
      sr.Close();
      }
      if (!string.IsNullOrEmpty(result))
      {
      var jsonSerializer = new JavaScriptSerializer();
      Results.Text = result;
     // var tokenData = jsonSerializer.Deserialize<GotoMeetingData>(result);
      //  txt_AccessCode.Text = tokenData.Access_Token;
      //return tokenData.Access_Token;
      }

But dint help.
Getting error 401 unauthorized
Rajiv