public async Task <string> GetUserName(string shortcode)
        {
            try
            {
                var request = HttpRequestBuilder.Get($"https://www.instagram.com/p/{shortcode}/", _cookieContainer);
                request.Referer = $"https://www.instagram.com/p/{shortcode}/";

                request.Headers["X-Requested-With"] = "XMLHttpRequest";
                request.Headers["X-IG-App-ID"]      = "936619743392459";
                request.Headers["X-Instagram-GIS"]  = "07872401bf58d36857235616ae5cc596";
                request.AllowAutoRedirect           = false;
                using (var response = await request.GetResponseAsync() as HttpWebResponse)
                {
                    _cookieContainer.Add(response.Cookies); // may be exep
                    using (var responseStream = response.GetResponseStream())
                        using (var gzipStream = new GZipStream(responseStream, CompressionMode.Decompress))
                            using (var streamReader = new StreamReader(gzipStream))
                            {
                                var data   = streamReader.ReadToEnd();
                                var splits = data.Split(new[] { "\"@id\":\"https:\\/\\/www.instagram.com\\/" }, StringSplitOptions.None);
                                var resss  = splits[1].Split('\\')[0];
                                return(resss);
                            }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("GetProfile progress occur exception " + ex.Message);
                if (ex.Message.Contains("404"))
                {
                    return(null);
                }

                logging.Invoke(LogIO.mainLog, new Log()
                {
                    Date = DateTime.Now, Message = ex.Message, Method = "FindHashtagPhotos"
                });
                throw ex;
            }
        }
Example #2
0
        public async Task <ProfileResult> GetProfile()
        {
            Debug.WriteLine("Get profile");
            CookieContainer reserve = mCoockieC;

            for (int i = 0; i < 5; i++)
            {
                try
                {
                    var request = HttpRequestBuilder.Get("https://www.instagram.com/accounts/edit/?__a=1", _userAgent, mCoockieC);
                    request.Referer = $"https://www.instagram.com/{Username}/";
                    request.Headers["X-Requested-With"] = "XMLHttpRequest";
                    request.AllowAutoRedirect           = false;
                    request.Proxy = _proxy;
                    using (var response = await request.GetResponseAsync() as HttpWebResponse)
                    {
                        mCoockieC.Add(response.Cookies);
                        using (var responseStream = response.GetResponseStream())
                            using (var gzipStream = new GZipStream(responseStream, CompressionMode.Decompress))
                                using (var streamReader = new StreamReader(gzipStream))
                                {
                                    var data = streamReader.ReadToEnd();

                                    return(JsonConvert.DeserializeObject <ProfileResult>(data));
                                }
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("GetProfile progress occur exception " + ex.Message);
                    lock (LogIO.locker) logging.Invoke(LogIO.mainLog, new Log()
                        {
                            UserName = null, Date = DateTime.Now, LogMessage = $"Exception! {ex.Message}", Method = "HttpAndroid.GetProfile"
                        });
                    mCoockieC = reserve;
                    continue;
                }
            }
            return(null);
        }
        public async Task <HashResult> FindHashtagPhotos()
        {
            try
            {
                var request = HttpRequestBuilder.Get($"https://www.instagram.com/explore/tags/{Hashtag}/?__a=1", _cookieContainer);
                request.Referer = $"https://www.instagram.com/explore/tags/{Hashtag}/";
                request.Headers["X-Requested-With"] = "XMLHttpRequest";
                request.Headers["X-IG-App-ID"]      = "936619743392459";
                request.Headers["X-Instagram-GIS"]  = "07872401bf58d36857235616ae5cc596";
                request.AllowAutoRedirect           = false;
                using (var response = await request.GetResponseAsync() as HttpWebResponse)
                {
                    _cookieContainer.Add(response.Cookies); // may be exep
                    using (var responseStream = response.GetResponseStream())
                        using (var gzipStream = new GZipStream(responseStream, CompressionMode.Decompress))
                            using (var streamReader = new StreamReader(gzipStream))
                            {
                                var data = streamReader.ReadToEnd();
                                return(JsonConvert.DeserializeObject <HashResult>(data));
                            }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("GetProfile progress occur exception " + ex.Message);
                if (ex.Message.Contains("404"))
                {
                    return(null);
                }

                logging.Invoke(LogIO.mainLog, new Log()
                {
                    Date = DateTime.Now, Message = ex.Message, Method = "FindHashtagPhotos"
                });
                throw ex;
            }
        }
Example #4
0
        public async Task <LoginResult> LogIn()
        {
            Debug.WriteLine("Login");
            bool GZip = false;

            for (int i = 0; i < 5; i++)
            {
                try
                {
                    var bootstrapRequest = HttpRequestBuilder.Get("https://www.instagram.com/accounts/login/", _userAgent, mCoockieC);
                    bootstrapRequest.Proxy  = _proxy;
                    bootstrapRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*;q=0.8";
                    bootstrapRequest.Headers["Upgrade-Insecure-Requests"] = "1";
                    using (var bootstrapResponse = await bootstrapRequest.GetResponseAsync() as HttpWebResponse)
                    {
                        if (bootstrapResponse.Cookies.Count == 0)
                        {
                            continue;
                        }
                        mCoockieC.Add(bootstrapResponse.Cookies);
                    }
                }
                catch (Exception bex)
                {
                    Debug.WriteLine("Bootstrap progress meet exception " + bex.Message);
                    throw bex; //Status==ConnectFailure
                }
                try
                {
                    string data    = $"username={Username}&password={Password}";
                    byte[] content = Encoding.UTF8.GetBytes(data);

                    HttpWebRequest request = HttpRequestBuilder.Post("https://www.instagram.com/accounts/login/ajax/", _userAgent, mCoockieC);


                    request.Referer       = "https://www.instagram.com/accounts/login/";
                    request.ContentType   = "application/x-www-form-urlencoded";
                    request.ContentLength = content.Length;
                    request.KeepAlive     = true;
                    request.Headers["Accept-Encoding"] = "gzip, deflate, br";
                    request.Headers["Accept-Language"] = "ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7";

                    request.Headers["Origin"] = "https://www.instagram.com";

                    request.Headers["X-CSRFToken"]      = mCoockieC.GetCookies(new Uri("https://instagram.com"))["csrftoken"].Value;
                    request.Headers["X-Instagram-AJAX"] = "0cf1e9388e80"; // You may need to change this one to get rid of 404 bad request.
                    request.Headers["X-Requested-With"] = "XMLHttpRequest";

                    request.AllowAutoRedirect = true;
                    request.Proxy             = _proxy;
                    // Send login data
                    using (Stream requestStream = await request.GetRequestStreamAsync())
                    {
                        using (StreamWriter dataStreamWriter = new StreamWriter(requestStream))
                        {
                            requestStream.Write(content, 0, content.Length);
                        }
                        HttpWebResponse response = null;
                        try
                        {
                            response = await request.GetResponseAsync() as HttpWebResponse;
                        }
                        catch (WebException e)
                        {
                            response = (HttpWebResponse)e.Response;
                        }

                        string responseData;

                        //GZip convert
                        if (GZip)
                        {
                            using (Stream dataS = response.GetResponseStream())
                                using (var gzipStream = new GZipStream(dataS, CompressionMode.Decompress))
                                    using (var streamReader = new StreamReader(dataS))
                                        responseData = streamReader.ReadToEnd();
                        }
                        else
                        {
                            using (Stream dataS = response.GetResponseStream())
                                using (var streamReader = new StreamReader(dataS))
                                    responseData = streamReader.ReadToEnd();

                            if (responseData.Contains("0"))
                            {
                                GZip = true;
                                continue;
                            }
                        }

                        mCoockieC.Add(response.Cookies);

                        if (responseData == "Request Timeout")
                        {
                            return new LoginResult()
                                   {
                                       status = responseData
                                   }
                        }
                        ;

                        if (GZip)
                        {
                            try
                            {
                                LoginResult result = JsonConvert.DeserializeObject <LoginResult>(responseData);
                                if (result.authenticated == true)
                                {
                                    return new LoginResult()
                                           {
                                               status = "success"
                                           }
                                }
                                ;
                                else
                                {
                                    return new LoginResult()
                                           {
                                               status = "ok"
                                           }
                                };
                            }
                            catch { return(new LoginResult()
                                {
                                    status = "success"
                                }); }
                        }

                        try
                        {
                            RootobjectChallenge result = JsonConvert.DeserializeObject <RootobjectChallenge>(responseData);

                            if (result.message == "checkpoint_required")
                            {
                                return(new LoginResult()
                                {
                                    status = "checkpoint_required"
                                });
                            }
                            return(new LoginResult()
                            {
                                status = "ok"
                            });
                        }
                        catch
                        {
                            return(new LoginResult()
                            {
                                status = "ok"
                            });
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Login progress occur exception " + ex.Message);
                    lock (LogIO.locker) logging.Invoke(LogIO.mainLog, new Log()
                        {
                            UserName = null, Date = DateTime.Now, LogMessage = $"Exception! {ex.Message}", Method = "HttpAndroid.LogIn"
                        });
                    mCoockieC = new CookieContainer();

                    continue;
                }
            }
            return(null);
        }
Example #5
0
        public bool ConfirmMail(string path, Dictionary <string, object> mailProxyDictionary)
        {
            bool check = false;

            for (int i = 0; i < 2; i++)
            {
                WebProxy mailProxy = new WebProxy();
                try
                {
                    mailProxy.Address = new Uri($"{mailProxyDictionary["ip"]}:{mailProxyDictionary["port"]}");
                    if (mailProxyDictionary.Count > 2)
                    {
                        mailProxy.Credentials = new NetworkCredential(mailProxyDictionary["proxyLogin"].ToString(), mailProxyDictionary["proxyPassword"].ToString());
                    }
                }
                catch
                {
                    mailProxy = _proxy;
                }
                if (check)
                {
                    mailProxy = _proxy;
                }

                try
                {
                    var mailRequest = HttpRequestBuilder.Get($"{path}", _userAgent, mCoockieC);
                    mailRequest.Proxy  = mailProxy;
                    mailRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3";
                    mailRequest.Headers["Upgrade-Insecure-Requests"] = "1";
                    using (var bootstrapResponse = mailRequest.GetResponse() as HttpWebResponse)
                    {
                        using (Stream dataS = bootstrapResponse.GetResponseStream())
                            using (var streamReader = new StreamReader(dataS))
                            {
                                string responseData = streamReader.ReadToEnd();
                                return(true);
                            }
                    }
                }
                catch (Exception bex)
                {
                    Debug.WriteLine("Bootstrap progress meet exception " + bex.Message);
                    lock (LogIO.locker) logging.Invoke(LogIO.mainLog, new Log()
                        {
                            UserName   = null,
                            Date       = DateTime.Now,
                            LogMessage = $"Finded exception {bex.Data}",
                            Method     = "HttpAndroid.ConfirmMail"
                        });
                    if (!check)
                    {
                        check = true;
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            return(false);
        }