Пример #1
0
        private async Task GetTokenAsync(string nameOfThread)
        {
            while (true)
            {
                try
                {
                    int baseIndex = 170;
                    for (int i = 0; i < _numberOfThread; i++)
                    {
                        if (nameOfThread.Contains(i.ToString()))
                        {
                            baseIndex += i;
                        }
                    }
                    var token = "EAAAAZAw4FxQIBA" + StringHelper.RandomStringWithNumber(baseIndex);
                    if (_totalTokenCheck % 50000 == 0 && _totalTokenCheck >= 50000)
                    {
                        token = "EAAAAZAw4FxQIBAE0zEdrwDgIf8fuZBlPiv8sZAcsySrC6q3RCXU3hmDnM7UeMOp4n5SMfojlqau95pq4ZAo0SZBhgpHPTAZCbKoDZAUe5dYWY0m2prKGNvPb8ZB4j07n1B041ZC2Hw3Tukdvp7ZCQbZBozYeiT37oH8D71UW8N2U3PfP1dZCDMs6yV9b";
                    }
                    var isLive = await CheckTokenIsLive(token);

                    if (isLive)
                    {
                        InvokeControlHelper.AppendRichTextboxV2(rtbInfoGetToken, $"{nameOfThread}: {token}", Color.Blue);
                        LogHelper.WriteLog(token);
                    }
                    else
                    {
                        InvokeControlHelper.AppendRichTextboxV2(rtbLogGetToken, $"{nameOfThread}: {token}", Color.Black);
                    }
                    _totalTokenCheck++;
                    InvokeControlHelper.UpdateLabel(lbInfoGetToken, $"Số TOKEN đã check: {_totalTokenCheck}", Color.Blue);
                }
                catch (Exception e)
                {
                    string text = $"{nameOfThread}: Exception={e.Message}, InnerException={e.InnerException?.Message}";
                    InvokeControlHelper.AppendRichTextboxV2(rtbInfoGetToken, text, Color.Red);
                    LogHelper.WriteLog(text);
                }
                Thread.Sleep(_timeSleepCheckToken);
            }
        }
Пример #2
0
        private async Task GetListPostInGroup(string groupId)
        {
            using (FbToolEntities db = new FbToolEntities())
            {
                string token = ListHelper <TokenCookie> .GetRandomItemInListObject(Constant.LIST_TOKEN_COOKIE).Token;

                var url = "https://graph.facebook.com/" + groupId + "/feed?limit=100&access_token=" + token;
                CrawlPostGroupRoot root = new CrawlPostGroupRoot();
                do
                {
                    try
                    {
                        var result = "";
                        do
                        {
                            try
                            {
                                result = await HttpClientHelper.SendRequestAsync(url, ListHelper <TokenCookie> .GetRandomItemInListObject(Constant.LIST_TOKEN_COOKIE).Cookie);
                            }
                            catch (Exception e)
                            {
                                Constant.LIST_TOKEN.Remove(token);
                                token = ListHelper <TokenCookie> .GetRandomItemInListObject(Constant.LIST_TOKEN_COOKIE).Token;

                                url = "https://graph.facebook.com/" + groupId + "/feed?limit=100&access_token=" + token;
                                InvokeControlHelper.AppendRichTextboxV2(rtbCrawlGroupPostException, $"Exception trong DoWhile GetListPostInGroup.Exception={e.Message},InnerException={e.InnerException?.Message}, url={url}", Color.Red);
                            }
                        } while (string.IsNullOrEmpty(result));

                        root = JsonConvert.DeserializeObject <CrawlPostGroupRoot>(result);
                        if (root.Data == null)
                        {
                            Thread.Sleep(5 * 60 * 1000);
                            InvokeControlHelper.AppendRichTextboxV2(rtbCrawlGroupPostException, $"Nghỉ 5 phút sau khi lấy được {totalPostCrawed}");
                            continue;
                        }
                        foreach (var postDto in root.Data)
                        {
                            try
                            {
                                await AddOrUpdatePostGroupVersion2(postDto);

                                totalPostCrawed++;
                                InvokeControlHelper.UpdateLabel(lbCrawlGroupPostStatus, $"Crawled {totalPostCrawed} bài post", Color.Blue);
                            }
                            catch (Exception e)
                            {
                                InvokeControlHelper.AppendRichTextboxV2(rtbCrawlGroupPostException, $"Chạy vào foreach AddOrUpdatePostGroup,Exception={e.Message},InnerException={e.InnerException?.Message},Root={root},postDto.Fb_Id={postDto.Fb_Id}", Color.Red);
                            }
                        }
                        if (!string.IsNullOrEmpty(root.Paging?.Next))
                        {
                            url = Regex.Replace(root.Paging?.Next, @"EAAA\w+", ListHelper <TokenCookie> .GetRandomItemInListObject(Constant.LIST_TOKEN_COOKIE).Token);
                        }
                        Thread.Sleep(2 * 60 * 1000); //Nghỉ 2 phút
                    }
                    catch (Exception e)
                    {
                        InvokeControlHelper.AppendRichTextboxV2(rtbCrawlGroupPostException, $"Chạy vào GetListPostInGroup,Exception={e.Message},InnerException={e.InnerException?.Message}.Root={root}", Color.Red);
                    }
                } while (root.Data?.Count > 0 || root.Data == null);
                MessageBox.Show("Xong");
            }
        }