Harsh Gupta

Harsh Gupta

  • NA
  • 1
  • 1.1k

hotmail contacts fetch generate code error comes 401

Jan 13 2015 2:14 AM
  public ActionResult tryhotmaillogin()
  {
  try
  {


  Response.Redirect("https://oauth.live.com/authorize?client_id=" + cid + "&scope=wl.signin%20wl.basic&response_type=code&redirect_uri=http://www.joblisting.com/Network/tryhotmailcode");
  }
  catch (Exception e)
  {
  Response.Write(e.Message);
  }

  return View();
  }
  [HttpGet]
  public ActionResult tryhotmailcode(string code)
  {
  try
  {
  var request = WebRequest.Create("https://oauth.live.com/token?client_id=" + cid + "&redirect_uri=http://www.joblisting.com/Network/tryhotmailaccesstoken&client_secret=" + csec + "&code=" + code + "&grant_type=authorization_code");
  //string text = null;
  //var response = (HttpWebResponse)request.GetResponse();
  //request.ContentType = "application/json; charset=utf-8";


  //using (var sr = new StreamReader(response.GetResponseStream()))
  //{
  //  text = sr.ReadToEnd();
  //}
  //NameValueCollection responseCollection = System.Web.HttpUtility.ParseQueryString(text);

  //string token = responseCollection["access_token"];

  //ViewBag.token = token;
  //var request1 = WebRequest.Create("https://apis.live.net/v5.0/me?access_token=" + token);

  //var response1 = (HttpWebResponse)request1.GetResponse();

  //DataSet dshotmail = new DataSet();
  //var hotmailStream = new StreamReader(response1.GetResponseStream());
  //// dshotmail.ReadXml(hotmailStream);
  //ViewBag.Data = hotmailStream;

  }
  catch (Exception e)
  {
  Response.Write(e.Message);

  }
  return View();
  }
  public ActionResult tryhotmailaccesstoken(string AccessToken)
  {
  try
  {
  var request1 = WebRequest.Create("https://apis.live.net/v5.0/me?access_token=" + AccessToken);
  var response1 = (HttpWebResponse)request1.GetResponse();
  DataSet dshotmail = new DataSet();
  var hotmailStream = new StreamReader(response1.GetResponseStream());
  dshotmail.ReadXml(hotmailStream);
  ViewBag.list = dshotmail;
 
  }
  catch(Exception ex)
  {
  Response.Write(ex.Message);
 
  }
  return View();
  }