title: Youtube login using c#
body: <p>I want to login youtube using c#. I am using HttpWebRequest.
  Procedure I am following:</p>
  
  <ol>
  <li>load the login page using GET and parse GALX value</li>
  <li>POST username/password along with GALX</li>
  <li>get a meta refresh page, parse the url and load using GET</li>
  <li>in every step cookies are handled using CookieContainer</li>
  <li>UserAgent, ContentType etc header values are set and AllowAutoRedirect is true.</li>
  </ol>
  
  <p>now i am getting the following Javascript code as response.</p>
  
  <pre><code>    var Ga, G = G || {};
      G.a = { g: "cookie_missing", f: "cookie_found", h: "gaia_failure" };
      var Gb = /\s*;\s*/;
      var Gc = function () {
  
          try 
          {
              return new XMLHttpRequest
          }
          catch (a) 
          {
              for (var b = ["MSXML2.XMLHTTP.6.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"], c = 0; c &lt; b.length; c++)
                  try 
                  {
                      return new ActiveXObject(b[c])
                  }
                  catch (d) { }
          }
  
          return null
      },
  
      Gd = function () {
  
          this.d = Gc(); this.b = {}
      };
      Gd.prototype.oncomplete = function () { };
  
      Gd.prototype.send = function (a) {
  
          var b = [], c; 
          for (c in this.b) {
              var d = this.b[c];
              b.push(c + "=" + encodeURIComponent(d))
          }
          var b = b.join("&amp;"), e = this.d, f = this.oncomplete;
          e.open("POST", a, !0);
          e.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
          e.setRequestHeader("Content-length", "" + b.length);
          e.onreadystatechange = function () {
              4 == e.readyState &amp;&amp; f({ status: e.status, text: e.responseText })
          };
          e.send(b)
      };
      Gd.prototype.get = function (a) {
          var b = this.oncomplete, c = this.d; c.open("GET", a, !0);
          c.onreadystatechange = function () { 4 == c.readyState &amp;&amp; b({ status: c.status, text: c.responseText }) };
          c.send()
      };
      var Gf = function (a) {
          this.c = a; this.i = this.j();
          if (null == this.c) throw new Ge("Empty module name");
      };
      Ga = Gf.prototype;
      Ga.j = function () {
          var a = window.location.pathname;
          return a &amp;&amp; 0 == a.indexOf("/accounts") ? "/accounts/JsRemoteLog" : "/JsRemoteLog"
      };
      Ga.k = function (a, b, c) {
          for (var d = this.i, e = this.c || "", d = d + "?module=" + encodeURIComponent(e), a = a || "", d = d + "&amp;type=" + encodeURIComponent(a), b = b || "", d = d + "&amp;msg=" + encodeURIComponent(b), c = c || [], a = 0; a &lt; c.length; a++) d = d + "&amp;arg=" + encodeURIComponent(c[a]);
          try {
              var f = Math.floor(1E4 * Math.random()), d = d + "&amp;r=" + ("" + f)
          }
          catch (g) { }
          return d
      };
      Ga.send = function (a, b, c) {
          var d = new Gd; d.b = {};
          try {
              var e = this.k(a, b, c);
              d.get(e)
          } catch (f) { }
      };
      Ga.error = function (a, b) {
          this.send("ERROR", a, b)
      };
      Ga.warn = function (a, b) {
          this.send("WARN", a, b)
      };
      Ga.info = function (a, b) {
          this.send("INFO", a, b)
      };
      Ga.m = function (a) {
          var b = this;
          return function () {
              try {
                  return a.apply(null, arguments)
              }
              catch (c) {
                  throw b.error("Uncatched exception: " + c), c;
              }
          }
      };
  
      var Ge = function () { };
      G = G || {};
      G.e = G.e || new Gf("report_sid_status");
      G.l = function (a, b, c) {
          if (window.postMessage &amp;&amp; window.parent) {
              if (a) {
                  a:
                  {
                      if (document.cookie)
                          for (var a = b + "=", b = document.cookie.split(Gb), d = 0; d &lt; b.length; d++) {
                              var e = b[d], e = e.replace(/^\s+/, ""), e = e.replace(/\s+$/, "");
                              if (0 == e.indexOf(a)) {
                                  a = e.substr(a.length);
                                  break a
                              }
                          }
                      a = null
                  }
                  a = null == a ? G.a.g : G.a.f
              }
              else a = G.a.h; window.parent.postMessage(a, c)
          }
      };
  
      G_checkSidAndReport = G.e.m(G.l);
  
      G_checkSidAndReport('0', 'SID', 'https:\x2F\x2Faccounts.google.com');
  </code></pre>
  
  <p>what to do now? Using this procedure I can successfully login Gmail but not youtube. I think javascript is posting to the server but I am unable to figure out actually what is posting.</p>