使用c#登录Youtube

本文关键字:Youtube 登录 使用 | 更新日期: 2023-09-27 18:26:02

我想使用c#登录youtube。我正在使用HttpWebRequest。我遵循的程序:

  1. 使用GET加载登录页面并解析GALX值
  2. POST用户名/密码以及GALX
  3. 获取一个元刷新页面,解析url并使用get加载
  4. 在每一步中,都使用CookieContainer处理cookie
  5. 设置UserAgent、ContentType等标头值,并且AllowAutoRedirect为true

现在,我得到以下Javascript代码作为响应。

    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 < 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("&"), 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 && 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 && 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 && 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 + "&type=" + encodeURIComponent(a), b = b || "", d = d + "&msg=" + encodeURIComponent(b), c = c || [], a = 0; a < c.length; a++) d = d + "&arg=" + encodeURIComponent(c[a]);
        try {
            var f = Math.floor(1E4 * Math.random()), d = d + "&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 && window.parent) {
            if (a) {
                a:
                {
                    if (document.cookie)
                        for (var a = b + "=", b = document.cookie.split(Gb), d = 0; d < 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');

现在该怎么办?使用这个程序,我可以成功登录Gmail,但不能登录youtube。我认为javascript正在向服务器发布,但我无法弄清楚到底发布了什么。

使用c#登录Youtube

我在php的代码中也有同样的位置,如果你能弄清楚,请告诉我。我认为关键是在下面的函数中使用这些参数。

G.l=function(a='1',b='SID',c='https:'x2F'x2Faccounts.google.com'){
if(window.postMessage&&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)
}

}