예제 #1
0
        public static bool CheckTwitterToken(oAuthTwitter objoAuthTwitter, string txtvalue)
        {
            bool CheckTwitterToken = false;
            //oAuthTwitter oAuthTwt = new oAuthTwitter();
            Search search = new Search();

            try
            {
                JArray twitterSearchResult = search.Get_Search_Tweets(objoAuthTwitter, txtvalue);
                CheckTwitterToken = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return CheckTwitterToken;
        }
예제 #2
0
        public string getresults(string keyword)
        {
            User user = (User)Session["LoggedUser"];
            int i = 0;
            string searchRes = string.Empty;
            if (!string.IsNullOrEmpty(keyword))
            {
                DiscoverySearch dissearch = new DiscoverySearch();
                DiscoverySearchRepository dissearchrepo = new DiscoverySearchRepository();

                List<DiscoverySearch> discoveryList = dissearchrepo.getResultsFromKeyword(keyword);

                if (discoveryList.Count == 0)
                {

                    #region Twitter

                    try
                    {
                        oAuthTwitter oauth = new oAuthTwitter();
                        oauth.ConsumerKey = ConfigurationManager.AppSettings["consumerKey"].ToString();
                        oauth.ConsumerKeySecret = ConfigurationManager.AppSettings["consumerSecret"].ToString();
                        oauth.CallBackUrl = ConfigurationManager.AppSettings["callbackurl"].ToString();
                        TwitterAccountRepository twtAccRepo = new TwitterAccountRepository();
                        ArrayList alst = twtAccRepo.getAllTwitterAccounts();
                        foreach (TwitterAccount item in alst)
                        {
                            oauth.AccessToken = item.OAuthToken;
                            oauth.AccessTokenSecret = item.OAuthSecret;
                            oauth.TwitterUserId = item.TwitterUserId;
                            oauth.TwitterScreenName = item.TwitterScreenName;
                            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
                                {
                                    dissearch.CreatedTime = SocioBoard.Helper.Extensions.ParseTwitterTime(chile["created_at"].ToString().TrimStart('"').TrimEnd('"')); ;
                                    dissearch.EntryDate = DateTime.Now;
                                    dissearch.FromId = chile["user"]["id_str"].ToString().TrimStart('"').TrimEnd('"');
                                    dissearch.FromName = chile["user"]["screen_name"].ToString().TrimStart('"').TrimEnd('"');
                                    dissearch.ProfileImageUrl = chile["user"]["profile_image_url"].ToString().TrimStart('"').TrimEnd('"');
                                    dissearch.SearchKeyword = txtSearchText.Text;
                                    dissearch.Network = "twitter";
                                    dissearch.Message = chile["text"].ToString().TrimStart('"').TrimEnd('"');
                                    dissearch.MessageId = chile["id_str"].ToString().TrimStart('"').TrimEnd('"');
                                    dissearch.Id = Guid.NewGuid();
                                    dissearch.UserId = user.Id;

                                    if (!dissearchrepo.isKeywordPresent(dissearch.SearchKeyword, dissearch.MessageId))
                                    {
                                        dissearchrepo.addNewSearchResult(dissearch);
                                    }

                                    searchRes += this.BindData(dissearch, i);

                                    i++;
                                }
                                catch (Exception ex)
                                {
                                    logger.Error(ex.StackTrace);
                                    Console.WriteLine(ex.StackTrace);
                                }
                            }
                        }

                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.StackTrace);
                        Console.WriteLine(ex.StackTrace);
                    }
                    #endregion
                    #region Facebook
                    try
                    {
                        #region FacebookSearch
                        int j = 0;
                        string accesstoken = string.Empty;
                        FacebookAccountRepository fbAccRepo = new FacebookAccountRepository();
                        ArrayList asltFbAccount = fbAccRepo.getAllFacebookAccounts();
                        foreach (FacebookAccount item in asltFbAccount)
                        {
                            accesstoken = item.AccessToken;
                            break;
                        }

                        string facebookSearchUrl = "https://graph.facebook.com/search?q=" + txtSearchText.Text + " &type=post&access_token="+accesstoken;
                        var facerequest = (HttpWebRequest)WebRequest.Create(facebookSearchUrl);
                        facerequest.Method = "GET";
                        string outputface = string.Empty;
                        using (var response = facerequest.GetResponse())
                        {
                            using (var stream = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(1252)))
                            {
                                outputface = stream.ReadToEnd();
                            }
                        }
                        if (!outputface.StartsWith("["))
                            outputface = "[" + outputface + "]";

                        JArray facebookSearchResult = JArray.Parse(outputface);

                        foreach (var item in facebookSearchResult)
                        {
                            var data = item["data"];

                            foreach (var chile in data)
                            {
                                try
                                {
                                    dissearch.CreatedTime = DateTime.Parse(chile["created_time"].ToString());
                                    dissearch.EntryDate = DateTime.Now;
                                    dissearch.FromId = chile["from"]["id"].ToString();
                                    dissearch.FromName = chile["from"]["name"].ToString();
                                    dissearch.ProfileImageUrl = "http://graph.facebook.com/" + chile["from"]["id"] + "/picture?type=small";
                                    dissearch.SearchKeyword = txtSearchText.Text;
                                    dissearch.Network = "facebook";
                                    dissearch.Message = chile["message"].ToString();
                                    dissearch.MessageId = chile["id"].ToString();
                                    dissearch.Id = Guid.NewGuid();
                                    dissearch.UserId = user.Id;
                                    if (!dissearchrepo.isKeywordPresent(dissearch.SearchKeyword, dissearch.MessageId))
                                    {
                                        dissearchrepo.addNewSearchResult(dissearch);
                                    }
                                    searchRes += this.BindData(dissearch, i);
                                }
                                catch (Exception ex)
                                {
                                    logger.Error(ex.StackTrace);
                                    Console.WriteLine(ex.StackTrace);
                                }

                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.StackTrace);
                        Console.WriteLine(ex.StackTrace);
                    }
                        #endregion

                    #endregion
                }
                else
                {
                    foreach (DiscoverySearch item in discoveryList)
                    {
                        searchRes += this.BindData(item, i);
                        i++;
                    }
                }

            }
            return searchRes;
        }
예제 #3
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();
                ArrayList alst = twtAccRepo.getAllTwitterAccounts();
                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);
                    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.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);
                        }

                        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");
            }
        }