public void Trends(TwitterUser User)
        {
            string Trends = null;

            GlobusTwitterLib.Twitter.Core.SearchMethods.Search search = new GlobusTwitterLib.Twitter.Core.SearchMethods.Search();
            Trends = search.Trends(User);
        }
Beispiel #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;
        }
Beispiel #3
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;
        }
 public void Trends(TwitterUser User)
 {
     string Trends = null;
     GlobusTwitterLib.Twitter.Core.SearchMethods.Search search = new GlobusTwitterLib.Twitter.Core.SearchMethods.Search();
     Trends = search.Trends(User);
 }
        public List<search> GetSearchMethodForTwtUser(oAuthTwitter OAuth, string SearchKey, string pageindex)
        {
            search objSearch = new search();

            Twitter.Core.SearchMethods.Search search = new Twitter.Core.SearchMethods.Search();
            JObject jsonResult = search.SearchMethodForTwtUser(OAuth, SearchKey, pageindex);
             JArray data = (JArray)jsonResult["results"];

            if (data!=null)
            {
                foreach (var userdetails in data)
                {
                    objSearch.id = (string)userdetails["from_user_id_str"];
                    objSearch.link = (string)userdetails["profile_image_url"];
                    objSearch.authorObject.name = (string)userdetails["from_user"];
                    SearchMethod.Add(objSearch);
                } 
            }
            return SearchMethod;

        }
        /// <summary>
        /// ReTweet
        /// </summary>
        /// <param name="OAuth">OAuth Keys Token, TokenSecret, ConsumerKey, ConsumerSecret</param>
        /// <param name="UserToFollow">TweetId</param>
        /// <returns>Returm True If ReTweet Success</returns>
        //public bool ReTweetStatus(oAuthTwitter OAuth, string TweetId)
        //{
        //    try
        //    {
        //        Twitter.Core.StatusMethods.Status status = new Twitter.Core.StatusMethods.Status();
        //        xmlResult = status.ReTweetStatus(OAuth, TweetId);
        //        return true;
        //    }
        //    catch
        //    {
        //        return false;
        //    }
        //}

        #endregion

        #region Search
        /// <summary>
        /// Search
        /// </summary>
        /// <param name="OAuth">OAuth Keys Token, TokenSecret, ConsumerKey, ConsumerSecret</param>
        /// <param name="Count">SearchKey For Search</param>
        /// <returns>Return Search Result</returns>
        public List<search> GetSearchMethod(oAuthTwitter OAuth, string SearchKey,string pageindex)
        {
            search objSearch = new search();

            Twitter.Core.SearchMethods.Search search = new Twitter.Core.SearchMethods.Search();
            xmlResult = search.SearchMethod(OAuth, SearchKey, pageindex);
            XmlNodeList xmlNodeList = xmlResult.GetElementsByTagName("entry");

            foreach (XmlNode xn in xmlNodeList)
            {
                XmlElement idElement = (XmlElement)xn;
                objSearch.id = idElement.GetElementsByTagName("id")[0].InnerText.Replace("tag:search.twitter.com,2005:", "");

                XmlElement idPostedTime = (XmlElement)xn;
                objSearch.PostedTime = idElement.GetElementsByTagName("published")[0].InnerText;

                XmlElement imageUrlElement = (XmlElement)xn;
                objSearch.content = imageUrlElement.GetElementsByTagName("content")[0].InnerText;

                XmlElement followersCountElement = (XmlElement)xn;
                objSearch.link = followersCountElement.GetElementsByTagName("updated")[0].NextSibling.Attributes["href"].InnerText;

                XmlElement friendCountElement = (XmlElement)xn;
                string name = friendCountElement.GetElementsByTagName("name")[0].InnerText;
                int FirstPoint = name.IndexOf("(");
                objSearch.authorObject.name = name.Substring(0, FirstPoint).Replace("(", "").Replace(" ", "");

                SearchMethod.Add(objSearch);
            }
            return SearchMethod;

        }
        /// <summary>
        /// Search
        /// </summary>
        /// <param name="User">Twitter User And Password</param>
        /// <param name="Count">SearchKey For Search</param>
        /// <returns>Return Search Result</returns>
        public List<search> GetSearchMethod(TwitterUser User, string SearchKey)
        {
            search objSearch = new search();

            Twitter.Core.SearchMethods.Search search = new Twitter.Core.SearchMethods.Search();
            xmlResult = search.SearchMethod(User, SearchKey);
            XmlNodeList xmlNodeList = xmlResult.GetElementsByTagName("entry");

            foreach (XmlNode xn in xmlNodeList)
            {
                XmlElement idElement = (XmlElement)xn;
                objSearch.id = idElement.GetElementsByTagName("id")[0].InnerText; 

                XmlElement imageUrlElement = (XmlElement)xn;
                objSearch.content = imageUrlElement.GetElementsByTagName("content")[0].InnerText;

                XmlElement followersCountElement = (XmlElement)xn;
                objSearch.link = followersCountElement.GetElementsByTagName("updated")[0].NextSibling.Attributes["href"].InnerText;

                XmlElement friendCountElement = (XmlElement)xn;
                objSearch.authorObject.name = friendCountElement.GetElementsByTagName("name")[0].InnerText;

                SearchMethod.Add(objSearch);
            }
            return SearchMethod;

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