Ejemplo n.º 1
0
        public static IInstaApi BuildApi(string username = null, string password = null)
        {
            UserSessionData sessionData;

            if (string.IsNullOrEmpty(username))
            {
                sessionData = UserSessionData.ForUsername("FAKEUSER").WithPassword("FAKEPASS");
            }
            else
            {
                sessionData = new UserSessionData {
                    UserName = username, Password = password
                }
            };

            DebugLogger = new DebugLogger(LogLevel.All);
            var api = InstaApiBuilder.CreateBuilder()
                      .SetUser(sessionData)

#if DEBUG
                      .UseLogger(DebugLogger)
#endif

                      .Build();

            api.SetTimeout(TimeSpan.FromMinutes(2));

            //InstaApi = api;
            return(api);
        }
Ejemplo n.º 2
0
        public static IInstaApi BuildApi(string username = null, string password = null)
        {
            UserSessionData sessionData;

            if (string.IsNullOrEmpty(username))
            {
                sessionData = UserSessionData.ForUsername("FAKEUSER").WithPassword("FAKEPASS");
            }
            else
            {
                sessionData = new UserSessionData {
                    UserName = username, Password = password
                }
            };

            DebugLogger = new DebugLogger(LogLevel.All);
            var api = InstaApiBuilder.CreateBuilder()
                      .SetUser(sessionData)
                      //.SetDevice(new UniversalDevice())
#if DEBUG
                      .UseLogger(DebugLogger)
#endif

                      .Build();

            return(api);
        }
Ejemplo n.º 3
0
        static public IInstaApi BuildApi(string username = null, string password = null)
        {
            var fakeUserData = UserSessionData.ForUsername(username ?? "FAKEUSER").WithPassword(password ?? "FAKEPASS");

            return(InstaApiBuilder.CreateBuilder()
                   .SetUser(fakeUserData)
                   .Build());
        }
Ejemplo n.º 4
0
 IInstaApi BuildApi()
 {
     return(InstaApiBuilder.CreateBuilder()
            .SetUser(UserSessionData.ForUsername("FAKEUSERNAME").WithPassword("FAKEPASS"))
            .UseLogger(new DebugLogger(LogLevel.All))
            .SetRequestDelay(RequestDelay.FromSeconds(0, 1))
            // Session handler, set a file path to save/load your state/session data
            .SetSessionHandler(new FileSessionHandler()
     {
         FilePath = StateFile
     })
            .Build());
 }
Ejemplo n.º 5
0
        public static IInstaApi BuildApi(string username = null, string password = null)
        {
            UserSessionData sessionData = UserSessionData.ForUsername("FAKEUSER").WithPassword("FAKEPASS");
            var             api         = InstaApiBuilder.CreateBuilder()
                                          .SetUser(sessionData)
                                          .SetDevice(new UniversalDevice())
#if DEBUG
                                          .UseLogger(new DebugLogger(LogLevel.All))
#endif

                                          .Build();

            api.SetTimeout(TimeSpan.FromMinutes(1));
            return(api);
        }
Ejemplo n.º 6
0
        public AuthenticatedTestFixture()
        {
            ApiInstance =
                TestHelpers.GetDefaultInstaApiInstance(UserSessionData.ForUsername(_username).WithPassword(_password));
            const string stateFile = "state.bin";

            try
            {
                if (File.Exists(stateFile))
                {
                    Stream fs = File.OpenRead(stateFile);
                    fs.Seek(0, SeekOrigin.Begin);
                    ApiInstance.LoadStateDataFromStream(fs);
                    if (ApiInstance.IsUserAuthenticated)
                    {
                        return;
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            var loginTask = Task.Run(ApiInstance.LoginAsync);

            if (!loginTask.Wait(TimeSpan.FromSeconds(30)))
            {
                throw new Exception($"Unable to login, user: {_username}, password: {_password}.");
            }

            if (!loginTask.Result.Succeeded)
            {
                return;
            }
            var state = ApiInstance.GetStateDataAsStream();

            using (var fileStream = File.Create(stateFile))
            {
                state.Seek(0, SeekOrigin.Begin);
                state.CopyTo(fileStream);
            }
        }