Esempio n. 1
0
        /// <summary>
        /// 4. Twitter redirects back to this action where we finish creating the user
        /// </summary>
        public ActionResult AuthorizeCallback(string oauth_token, string oauth_verifier)
        {
            var requestToken = new OAuthRequestToken {
                Token = oauth_token
            };
            var service     = twitterFactory.Create();
            var accessToken = service.GetAccessToken(requestToken, oauth_verifier);

            service.AuthenticateWith(accessToken.Token, accessToken.TokenSecret);
            var twitterUser = service.VerifyCredentials();

            if (twitterUser == null)
            {
                return(HttpNotFound("Dude, Twitter has no idea who you are."));
            }

            var user = userRepository.GetByTwitterId(twitterUser.Id) ?? context.User;

            if (user == null)
            {
                return(HttpNotFound("I'm sorry, I don't remember seeing you before. Have we met?"));
            }

            user.AuthData = new TwitterAuthData
            {
                Secret = accessToken.TokenSecret, Token = accessToken.Token, TwitterId = twitterUser.Id
            };
            user.TwitterHandles.Add(twitterUser.ScreenName);
            userRepository.Save(user);

            return(RedirectToAction("Index"));
        }
Esempio n. 2
0
 public AuthenticatedHomePageViewModel(User user, ITwitterFactory twitter)
 {
     Email = user.Email;
     var twitterUser = twitter.CurrentUser;
     if (twitterUser == null) throw new InvalidOperationException("twitterUser was not found or was just null");
     ProfilePicUrl = twitterUser.ProfileImageUrl;
     TwitterHandle = twitterUser.ScreenName;
     var service = twitter.Create();
     if (twitterUser == null) throw new InvalidOperationException("Twitter service was null or just couldn't be constructed");
     Favorites = service.ListFavoriteTweets(2, 5);
 }
Esempio n. 3
0
        public AuthenticatedHomePageViewModel(User user, ITwitterFactory twitter)
        {
            Email = user.Email;
            var twitterUser = twitter.CurrentUser;

            if (twitterUser == null)
            {
                throw new InvalidOperationException("twitterUser was not found or was just null");
            }
            ProfilePicUrl = twitterUser.ProfileImageUrl;
            TwitterHandle = twitterUser.ScreenName;
            var service = twitter.Create();

            if (twitterUser == null)
            {
                throw new InvalidOperationException("Twitter service was null or just couldn't be constructed");
            }
            Favorites = service.ListFavoriteTweets(2, 5);
        }
Esempio n. 4
0
        public List <Tweet> GetTwitters()
        {
            List <Tweet> twits   = new List <Tweet>();
            var          twitter = new Twitter("xNBdzXy7tkyD1kstIDcg", "0nSriIwDZkFR7qcf6nsnQh3bqecn7IGoTqpIr8Xk6gc",
                                               "1451422718-kwIAaVppRGys6dltQXKIUt39vNbIg5e4PFD1Rgu",
                                               "1LPbBbwYcAELk3dl50WIwZMp38gt2wWGwkOkzVQGQM");

            var responseTwitter = twitter.GetTweets(MyConfigurationManager.GetTweeterQuery());

            JObject jobjectTwitter1 = JObject.Parse(responseTwitter);

            var resultado12 = jobjectTwitter1["statuses"];

            var twittsList2 = resultado12.ToList();

            foreach (JToken twitt in twittsList2)
            {
                var text     = twitt["text"].ToString();
                var textUper = text.ToUpper();
                var uperText = text.ToString().ToUpper();


                bool containsForbiddenWords = ContainsForbiddenWords(textUper);
                bool containsKeyWords       = ContainsKeyWords(uperText);

                if (!containsForbiddenWords && containsKeyWords)
                {
                    var          user       = twitt["user"];
                    var          screenName = user["screen_name"].ToString();
                    var          name       = user["name"].ToString();
                    var          date       = twitt["created_at"].ToString().Replace("\\", "").Replace("\"", "");
                    const string format     = "ddd MMM dd HH:mm:ss zzzz yyyy";
                    var          realtime   = DateTime.ParseExact(date, format, CultureInfo.InvariantCulture);
                    var          utcTime    = GlobalWebData.ToUniversalTime(realtime);//.Subtract(System.TimeSpan.FromHours(System.Convert.ToDouble(2)));
                    twits.Add(twitterFactory.Create(name, screenName, text, utcTime));
                }
            }


            return(twits);
        }
Esempio n. 5
0
        public IEnumerable <TwitterStatus> GetFavoritesForUser(User user)
        {
            var twitterService = twitterFactory.Create(user);

            return(twitterService.ListFavoriteTweets());
        }