static void Main(string[] args)
        {
            AntiCaptchaApi         AntiCaptchaApi = new AntiCaptchaApi("https://api.anti-captcha.com", "Client Key");
            NoCaptchaTaskProxyless captchaTask    = new NoCaptchaTaskProxyless("Website Url", "Website Key");

            System.Threading.Tasks.Task.Run(async() =>
            {
                // Get balance
                BalanceResponse balanceResponse = await AntiCaptchaApi.GetBalanceAsync();
                float balance = balanceResponse.Balance;

                // Make a task
                TaskResponse response = await AntiCaptchaApi.CreateTaskAsync(captchaTask);
                int taskId            = response.TaskId;

                // Get the task result
                TaskResult <NoCaptchaSolution> taskResult = null;
                do
                {
                    try
                    {
                        taskResult = await AntiCaptchaApi.GetTaskResultAsync <NoCaptchaSolution>(taskId);
                        // Wait 0.5 seconds before requesting again
                        System.Threading.Tasks.Task.Delay(500).Wait();
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }while (taskResult != null && taskResult.Status != "ready");
            });

            Console.Read();
        }
Beispiel #2
0
        private void CreateApiTask(AntiCaptchaTask task, RecaptchaParameter parameter)
        {
            task.Id = null;

            Task <string> apiTask = AntiCaptchaApi.CreateReCaptchaTask(ApiKey, parameter.SiteKey, parameter.SitePath, CancelToken);

            lock (m_lock)
            {
                m_tasks[task] = apiTask;
            }
        }
Beispiel #3
0
        private void CheckTasksStatus()
        {
            Dictionary <AntiCaptchaTask, Task <string> > allTasks = null;
            List <AntiCaptchaTask> goodTasks     = new List <AntiCaptchaTask>();
            List <AntiCaptchaTask> badTasks      = new List <AntiCaptchaTask>();
            List <AntiCaptchaTask> canceledTasks = new List <AntiCaptchaTask>();

            lock (m_lock)
            {
                allTasks = new Dictionary <AntiCaptchaTask, Task <string> >(m_tasks);
            }

            foreach (KeyValuePair <AntiCaptchaTask, Task <string> > pair in allTasks)
            {
                if (pair.Value.IsCompleted)
                {
                    if (!pair.Value.IsCanceled)
                    {
                        string id = pair.Value.Result;

                        if (id != null)
                        {
                            pair.Key.Id = id;
                            goodTasks.Add(pair.Key);
                        }
                        else
                        {
                            badTasks.Add(pair.Key);
                        }
                    }
                    else
                    {
                        pair.Key.Solution = null;
                        canceledTasks.Add(pair.Key);
                    }
                }
            }

            if (goodTasks.Any())
            {
                Task <Dictionary <string, string> > checkTask = AntiCaptchaApi.CheckReCaptchaTask(ApiKey, goodTasks.Select(t => t.Id).ToList(), CancelToken);

                Dictionary <string, string> solutions = null;

                try
                {
                    checkTask.Wait(CancelToken);
                    solutions = checkTask.Result;
                }
                catch (Exception e)
                {
                }

                if (solutions != null)
                {
                    foreach (KeyValuePair <string, string> pair in solutions)
                    {
                        AntiCaptchaTask task = goodTasks.First(t => t.Id == pair.Key);

                        if (pair.Value == AntiCaptchaResponseCode.ERROR_CAPTCHA_UNSOLVABLE.ToString() ||
                            pair.Value == AntiCaptchaResponseCode.ERROR_NO_SUCH_CAPCHA_ID.ToString())
                        {
                            goodTasks.Remove(task);
                            badTasks.Add(task);
                        }
                        else if (pair.Value != AntiCaptchaResponseCode.CAPTCHA_IS_NOT_READY.ToString())
                        {
                            task.Solution = pair.Value.Substring(1);
                        }
                    }
                }
            }

            lock (m_lock)
            {
                m_tasks = m_tasks.Where(p => (!goodTasks.Contains(p.Key) || p.Key.Solution == null) && !canceledTasks.Contains(p.Key)).ToDictionary(p => p.Key, p => p.Value);
            }

            foreach (AntiCaptchaTask task in badTasks)
            {
                task.Solution = null;
                //CreateApiTask(task, task.Parameter);
            }

            lock (m_lock)
            {
                if (m_tasks.Any())
                {
                    m_checkTasksTimer.Change(m_checkPeriod, Timeout.Infinite);
                }
                else
                {
                    m_isCheckTimerLaunched = false;
                }
            }
        }