Ejemplo n.º 1
0
        /// <summary>
        ///     Create new API instance
        /// </summary>
        /// <returns>
        ///     API instance
        /// </returns>
        /// <exception cref="ArgumentNullException">User auth data must be specified</exception>
        public IInstaApi Build()
        {
            if (_user == null)
            {
                throw new ArgumentNullException("User auth data must be specified");
            }
            if (_httpClient == null)
            {
                _httpClient = new HttpClient(_httpHandler)
                {
                    BaseAddress = new Uri(InstaApiConstants.INSTAGRAM_URL)
                }
            }
            ;

            if (_requestMessage == null)
            {
                if (_device == null)
                {
                    _device = AndroidDeviceGenerator.GetRandomAndroidDevice();
                }
                _requestMessage = new ApiRequestMessage
                {
                    PhoneId  = _device.PhoneGuid.ToString(),
                    Guid     = _device.DeviceGuid,
                    Password = _user?.Password,
                    Username = _user?.UserName,
                    DeviceId = ApiRequestMessage.GenerateDeviceId(),
                    AdId     = _device.AdId.ToString()
                };
            }

            if (string.IsNullOrEmpty(_requestMessage.Password))
            {
                _requestMessage.Password = _user?.Password;
            }
            if (string.IsNullOrEmpty(_requestMessage.Username))
            {
                _requestMessage.Username = _user?.UserName;
            }

            if (_device == null && !string.IsNullOrEmpty(_requestMessage.DeviceId))
            {
                _device = AndroidDeviceGenerator.GetById(_requestMessage.DeviceId);
            }
            if (_device == null)
            {
                AndroidDeviceGenerator.GetRandomAndroidDevice();
            }

            if (_httpRequestProcessor == null)
            {
                _httpRequestProcessor =
                    new HttpRequestProcessor(_delay, _httpClient, _httpHandler, _requestMessage, _logger);
            }

            var instaApi = new InstaApi(_user, _logger, _device, _httpRequestProcessor);

            return(instaApi);
        }
Ejemplo n.º 2
0
        public IInstaApi Build()
        {
            if (_httpClient == null)
            {
                _httpClient             = new HttpClient(_httpHandler);
                _httpClient.BaseAddress = new Uri(InstaApiConstants.INSTAGRAM_URL);
            }
            AndroidDevice device = null;

            if (_requestMessage == null)
            {
                device          = AndroidDeviceGenerator.GetRandomAndroidDevice();
                _requestMessage = new ApiRequestMessage
                {
                    phone_id  = device.PhoneGuid.ToString(),
                    guid      = device.DeviceGuid,
                    password  = _user?.Password,
                    username  = _user?.UserName,
                    device_id = ApiRequestMessage.GenerateDeviceId()
                };
            }
            var instaApi = new InstaApi(_user, _logger, _httpClient, _httpHandler, _requestMessage, device);

            return(instaApi);
        }
Ejemplo n.º 3
0
        public static string GenerateFacebookUserAgent()
        {
            var deviceInfo = AndroidDeviceGenerator.GetRandomAndroidDevice();

            //Mozilla/5.0 (Linux; Android 7.0; PRA-LA1 Build/HONORPRA-LA1; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/69.0.3497.100 Mobile Safari/537.36

            return(string.Format(InstaApiConstants.FACEBOOK_USER_AGENT,
                                 deviceInfo.AndroidVer.VersionNumber, deviceInfo.DeviceModelIdentifier,
                                 $"{deviceInfo.AndroidBoardName}{deviceInfo.DeviceModel}"));
        }
 /// <summary>
 ///     Set custom android device.
 ///     <para>Note: this is optional, if you didn't set this, InstagramApiSharp will choose random device.</para>
 /// </summary>
 /// <param name="androidDevice">Android device</param>
 /// <returns>API Builder</returns>
 public IInstaApiBuilder SetDevice(AndroidDevice androidDevice)
 {
     if (androidDevice == null)
     {
         _device = AndroidDeviceGenerator.GetRandomAndroidDevice();
     }
     else
     {
         _device = androidDevice;
     }
     return(this);
 }
Ejemplo n.º 5
0
        public IInstaApi Build()
        {
            if (_httpClient == null)
            {
                _httpClient = new HttpClient(_httpHandler)
                {
                    BaseAddress = new Uri(InstaApiConstants.INSTAGRAM_URL)
                }
            }
            ;

            if (_requestMessage == null)
            {
                _device         = AndroidDeviceGenerator.GetRandomAndroidDevice();
                _requestMessage = new ApiRequestMessage
                {
                    phone_id  = _device.PhoneGuid.ToString(),
                    guid      = _device.DeviceGuid,
                    password  = _user?.Password,
                    username  = _user?.UserName,
                    device_id = ApiRequestMessage.GenerateDeviceId()
                };
            }


            if (string.IsNullOrEmpty(_requestMessage.password))
            {
                _requestMessage.password = _user?.Password;
            }
            if (string.IsNullOrEmpty(_requestMessage.username))
            {
                _requestMessage.username = _user?.UserName;
            }
            if (_device == null && !string.IsNullOrEmpty(_requestMessage.device_id))
            {
                _device = AndroidDeviceGenerator.GetById(_requestMessage.device_id);
            }
            if (_device == null)
            {
                AndroidDeviceGenerator.GetRandomAndroidDevice();
            }

            if (_httpRequestProcessor == null)
            {
                _httpRequestProcessor =
                    new HttpRequestProcessor(_delay, _httpClient, _httpHandler, _requestMessage, _logger);
            }

            var instaApi = new InstaApi(_user, _logger, _device, _httpRequestProcessor);

            return(instaApi);
        }
Ejemplo n.º 6
0
        private void GenerateDevice()
        {
            AndroidDevice device = AndroidDeviceGenerator.GetRandomAndroidDevice();

            string user = "", password = "";

            user     = usernameText.Text;
            password = passwordText.Text;

            ApiRequestMessage _requestMessage = new ApiRequestMessage
            {
                phone_id  = device.PhoneGuid.ToString(),
                guid      = device.DeviceGuid,
                password  = password,
                username  = user,
                device_id = AndroidDeviceGenerator.HTC10
            };

            HttpClient client = new System.Net.Http.HttpClient();

            client.BaseAddress = new Uri("https://i.instagram.com");

            UserSessionData userConfig = new UserSessionData();

            userConfig.UserName = user;
            userConfig.Password = password;

            HttpClientHandler httpClientHandler = new HttpClientHandler();


            /*Add this if you want to add proxy support.*/

            /*if (proxyFound)
             * {
             *  httpClientHandler.UseProxy = true;
             * IWebProxy proxy = new WebProxy("proxy");
             *  httpClientHandler.Proxy = proxy;
             * }
             */

            api = new InstaApi(userConfig, null, client, httpClientHandler, _requestMessage, device);

            InstagramLogin();
        }
        /// <summary>
        ///     Create new API instance
        /// </summary>
        /// <returns>
        ///     API instance
        /// </returns>
        /// <exception cref="ArgumentNullException">User auth data must be specified</exception>
        public IInstaApi Build()
        {
            if (_user == null)
            {
                _user = UserSessionData.Empty;
            }

            if (_httpHandler == null)
            {
                _httpHandler = new HttpClientHandler();
            }

            if (_httpClient == null)
            {
                _httpClient = new HttpClient(_httpHandler)
                {
                    BaseAddress = new Uri(InstaApiConstants.INSTAGRAM_URL)
                }
            }
            ;

            if (_requestMessage == null)
            {
                if (_device == null)
                {
                    _device = AndroidDeviceGenerator.GetRandomAndroidDevice();
                }
                _requestMessage = new ApiRequestMessage
                {
                    PhoneId  = _device.PhoneGuid.ToString(),
                    Guid     = _device.DeviceGuid,
                    Password = _user?.Password,
                    Username = _user?.UserName,
                    DeviceId = ApiRequestMessage.GenerateDeviceId(),
                    AdId     = _device.AdId.ToString()
                };
            }

            if (string.IsNullOrEmpty(_requestMessage.Password))
            {
                _requestMessage.Password = _user?.Password;
            }
            if (string.IsNullOrEmpty(_requestMessage.Username))
            {
                _requestMessage.Username = _user?.UserName;
            }

            try
            {
                InstaApiConstants.TIMEZONE_OFFSET = int.Parse(DateTimeOffset.Now.Offset.TotalSeconds.ToString());
            }
            catch { }

            if (_httpRequestProcessor == null)
            {
                _httpRequestProcessor =
                    new HttpRequestProcessor(_delay, _httpClient, _httpHandler, _requestMessage, _logger);
            }

            if (_apiVersionType == null)
            {
                _apiVersionType = InstaApiVersionType.Version76;
            }

            var instaApi = new InstaApi(_user, _logger, _device, _httpRequestProcessor, _apiVersionType.Value);

            if (_sessionHandler != null)
            {
                _sessionHandler.InstaApi = instaApi;
                instaApi.SessionHandler  = _sessionHandler;
            }
            return(instaApi);
        }
Ejemplo n.º 8
0
        /// <summary>
        ///     Create new API instance
        /// </summary>
        /// <returns>
        ///     API instance
        /// </returns>
        /// <exception cref="ArgumentNullException">User auth data must be specified</exception>
        public IInstaApi Build()
        {
            if (user == null)
            {
                user = UserSessionData.Empty;
            }

            if (httpHandler == null)
            {
                httpHandler = new HttpClientHandler();
            }

            if (httpClient == null)
            {
                httpClient = new HttpClient(httpHandler)
                {
                    BaseAddress = new Uri(InstaApiConstants.InstagramUrl)
                };
            }

            if (requestMessage == null)
            {
                if (device == null)
                {
                    device = AndroidDeviceGenerator.GetRandomAndroidDevice();
                }

                requestMessage = new ApiRequestMessage
                {
                    PhoneId  = device.PhoneGuid.ToString(),
                    Guid     = device.DeviceGuid,
                    Password = user?.Password,
                    Username = user?.UserName,
                    DeviceId = ApiRequestMessage.GenerateDeviceId(),
                    AdId     = device.AdId.ToString()
                };
            }

            if (string.IsNullOrEmpty(requestMessage.Password))
            {
                requestMessage.Password = user?.Password;
            }

            if (string.IsNullOrEmpty(requestMessage.Username))
            {
                requestMessage.Username = user?.UserName;
            }

            try
            {
                InstaApiConstants.TimezoneOffset = (int)DateTimeOffset.Now.Offset.TotalSeconds;
            }
            catch
            {
            }

            if (httpRequestProcessor == null)
            {
                httpRequestProcessor = new HttpRequestProcessor(delay, httpClient, httpHandler, requestMessage, loggerFactory?.CreateLogger <HttpRequestProcessor>());
            }

            if (apiVersionType == null)
            {
                apiVersionType = InstaApiVersionType.Version86;
            }

            var instaApi = new InstaApi(loggerFactory?.CreateLogger <InstaApi>(),
                                        httpRequestProcessor,
                                        user,
                                        apiVersionType.Value,
                                        device,
                                        new CommonResilience(loggerFactory?.CreateLogger <CommonResilience>(),
                                                             ResilienceConfig.GenerateCommon()));

            return(instaApi);
        }