コード例 #1
0
        public string contactSearchTwitter(string keyword)
        {
            List <Domain.Socioboard.Domain.DiscoverySearch> lstDiscoverySearch = new List <Domain.Socioboard.Domain.DiscoverySearch>();
            string profileid = string.Empty;

            try
            {
                oAuthTwitter oauth = new oAuthTwitter();
                Twitter      obj   = new Twitter();

                TwitterAccountRepository twtAccRepo = new TwitterAccountRepository();
                //ArrayList alst = twtAccRepo.getAllTwitterAccounts();
                List <Domain.Socioboard.Domain.TwitterAccount> alst = twtAccRepo.getTwtAccount();
                foreach (Domain.Socioboard.Domain.TwitterAccount item in alst)
                {
                    oauth.AccessToken       = item.OAuthToken;
                    oauth.AccessTokenSecret = item.OAuthSecret;
                    oauth.TwitterUserId     = item.TwitterUserId;
                    oauth.TwitterScreenName = item.TwitterScreenName;
                    obj.SetCofigDetailsForTwitter(oauth);
                    try
                    {
                        Users  _Users         = new Users();
                        JArray _AccountVerify = _Users.Get_Account_Verify_Credentials(oauth);
                        string id             = _AccountVerify["id_str"].ToString();
                        break;
                    }
                    catch (Exception ex)
                    {
                    }

                    //if (this.CheckTwitterToken(oauth, keyword))
                    //{
                    //    break;
                    //}
                }

                Users  twtUser             = new Users();
                JArray twitterSearchResult = twtUser.Get_Users_Search(oauth, keyword, "20");
                foreach (var item in twitterSearchResult)
                {
                    try
                    {
                        objDiscoverySearch               = new Domain.Socioboard.Domain.DiscoverySearch();
                        objDiscoverySearch.FromId        = item["id_str"].ToString();
                        objDiscoverySearch.FromName      = item["screen_name"].ToString();
                        objDiscoverySearch.SearchKeyword = keyword;
                        try
                        {
                            objDiscoverySearch.ProfileImageUrl = item["profile_image_url_https"].ToString();
                        }
                        catch { }
                        lstDiscoverySearch.Add(objDiscoverySearch);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                }


                return(new JavaScriptSerializer().Serialize(lstDiscoverySearch));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                return(new JavaScriptSerializer().Serialize("Please try Again"));
            }
        }
コード例 #2
0
        public string DiscoverySearchTwitter(string UserId, string keyword)
        {
            List <Domain.Socioboard.Domain.DiscoverySearch> lstDiscoverySearch = new List <Domain.Socioboard.Domain.DiscoverySearch>();
            string profileid = string.Empty;

            try
            {
                oAuthTwitter oauth = new oAuthTwitter();
                Twitter      obj   = new Twitter();

                TwitterAccountRepository twtAccRepo = new TwitterAccountRepository();
                List <Domain.Socioboard.Domain.TwitterAccount> alst = twtAccRepo.getTwtAccount();
                try
                {
                    objDiscoverySearch = new Domain.Socioboard.Domain.DiscoverySearch();
                    objDiscoverySearch.SearchKeyword = keyword;
                    objDiscoverySearch.Network       = "twitter";
                    objDiscoverySearch.Id            = Guid.NewGuid();
                    objDiscoverySearch.UserId        = Guid.Parse(UserId);

                    if (!dissearchrepo.isKeywordPresentforNetwork(objDiscoverySearch.SearchKeyword, objDiscoverySearch.Network))
                    {
                        dissearchrepo.addNewSearchResult(objDiscoverySearch);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }
                foreach (Domain.Socioboard.Domain.TwitterAccount item in alst)
                {
                    oauth.AccessToken       = item.OAuthToken;
                    oauth.AccessTokenSecret = item.OAuthSecret;
                    oauth.TwitterUserId     = item.TwitterUserId;
                    oauth.TwitterScreenName = item.TwitterScreenName;
                    obj.SetCofigDetailsForTwitter(oauth);
                    try
                    {
                        Users  _Users         = new Users();
                        JArray _AccountVerify = _Users.Get_Account_Verify_Credentials(oauth);
                        string id             = _AccountVerify["id_str"].ToString();
                        break;
                    }
                    catch (Exception ex)
                    {
                    }
                    //if (this.CheckTwitterToken(oauth, keyword))
                    //{
                    //    break;
                    //}
                }

                Search search = new Search();
                JArray twitterSearchResult = search.Get_Search_Tweets(oauth, keyword);
                foreach (var item in twitterSearchResult)
                {
                    var results = item["statuses"];
                    foreach (var chile in results)
                    {
                        try
                        {
                            objDiscoverySearch                 = new Domain.Socioboard.Domain.DiscoverySearch();
                            objDiscoverySearch.CreatedTime     = Utility.ParseTwitterTime(chile["created_at"].ToString().TrimStart('"').TrimEnd('"'));;
                            objDiscoverySearch.EntryDate       = DateTime.Now;
                            objDiscoverySearch.FromId          = chile["user"]["id_str"].ToString().TrimStart('"').TrimEnd('"');
                            objDiscoverySearch.FromName        = chile["user"]["screen_name"].ToString().TrimStart('"').TrimEnd('"');
                            objDiscoverySearch.ProfileImageUrl = chile["user"]["profile_image_url"].ToString().TrimStart('"').TrimEnd('"');
                            objDiscoverySearch.SearchKeyword   = keyword;
                            objDiscoverySearch.Network         = "twitter";
                            objDiscoverySearch.Message         = chile["text"].ToString().TrimStart('"').TrimEnd('"');
                            objDiscoverySearch.MessageId       = chile["id_str"].ToString().TrimStart('"').TrimEnd('"');
                            objDiscoverySearch.Id              = Guid.NewGuid();
                            objDiscoverySearch.UserId          = Guid.Parse(UserId);

                            lstDiscoverySearch.Add(objDiscoverySearch);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.StackTrace);
                        }
                    }
                }
                return(new JavaScriptSerializer().Serialize(lstDiscoverySearch));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                return(new JavaScriptSerializer().Serialize("Please try Again"));
            }
        }