Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
3.9 kB
14
Indexable
Never
 public void LoginFacebookGetToken(Profile pro, GridRow row)
        {
            try
            {
                row.Status = "Load trang đăng nhập";
                string loginID = pro.UID;
                string datalogin = $"email={loginID}&password={pro.Password}&generate_session_cookies=1&locale=vi_VN&client_country_code=VN&access_token=275254692598279|585aec5b4c27376758abb7ffcb9db2af";


                string temp = PostAsync($"https://b-graph.facebook.com/auth/login", datalogin).Result;
                if (string.IsNullOrEmpty(temp))
                {
                    row.Status = "Lỗi mạng";
                    return;
                }
                temp = temp.Replace("  ", " ").Replace(" \"", "\"").Replace("\" ", "\"").Replace("\r", "").Replace("\n", "");
                string token = RegexMatch(temp, "access_token\":\"(.*?)\"").Groups[1].Value;
                if (string.IsNullOrEmpty(token))
                {
                    if (temp.IsContains("\"login_first_factor\":\"") || temp.IsContains("\"error_subcode\":1348162"))
                    {
                        if (!string.IsNullOrEmpty(pro.SecrectKey))
                        {
                            var tfa = new TwoFactorAuth();
                            string code = tfa.GetCode(pro.SecrectKey.Replace(" ", "").ToUpper());
                            row.Status = "Gửi 2FA : " + code;
                            string factor = RegexMatch(temp, "\"login_first_factor\":\"(.*?)\"").Groups[1].Value;
                            string data2fa = $"email={loginID}&password={pro.Password}&sim_serials=[]&credentials_type=two_factor&generate_session_cookies=1&locale=vi_VN&client_country_code=VN&twofactor_code={code}&userid={pro.UID}&first_factor={factor}&access_token=275254692598279|585aec5b4c27376758abb7ffcb9db2af";
                            temp = PostAsync($"https://b-graph.facebook.com/auth/login", data2fa).Result;
                            temp = temp.Replace(" \"", "\"").Replace("\" ", "\"").Replace("\r", "").Replace("\n", "").Replace("  ", " ");
                            token = RegexMatch(temp, "access_token\":\"(.*?)\"").Groups[1].Value;
                        }
                    }
                }
                if (string.IsNullOrEmpty(token))
                {
                    string er = RegexMatch(temp, "\"error_user_title\":\"(.*?)\"").Groups[1].Value;
                    if (string.IsNullOrEmpty(er)) er = temp;
                    er = RegexUnescape(er);
                    row.Status = er;
                    return;
                }
                //check token live
                string checktoken = Get($"https://graph.facebook.com/me/?access_token={token}").Result;
                if (!string.IsNullOrEmpty(checktoken))
                    checktoken = checktoken.Replace("  ", " ").Replace(" \"", "\"").Replace("\" ", "\"").Replace("\r", "").Replace("\n", "");
                if (!checktoken.IsContains("\"id\":\""))
                {
                    row.Status = "Get Token thất bại";
                    return;
                }
                row.Status = "Đăng nhập thành công";
                pro.Token = token;
                tokenss = token;
                string co = "";
                try
                {
                    dynamic stuff = JsonConvert.DeserializeObject(temp);
                    foreach (var no in stuff.session_cookies)
                    {
                        string name = no.name;
                        string value = no.value;
                        if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(value)) co += $"{name}={value};";
                    }
                }
                catch { }
                pro.Cookie = co;

            }
            catch { }

        }