Exemplo n.º 1
0
        public Response <Twitter> BuscarTweets()
        {
            var response = new Response <Twitter>();

            try
            {
                var auth = new MvcAuthorizer
                {
                    CredentialStore = new InMemoryCredentialStore
                    {
                        ConsumerKey      = "###############",
                        ConsumerSecret   = "##############",
                        OAuthToken       = OAuthKeys.TwitterAccessToken,
                        OAuthTokenSecret = OAuthKeys.TwitterAccessTokenSecret,
                    }
                };
                auth.AuthorizeAsync();

                var ctx = new TwitterContext(auth);

                List <Search> searchResponse =
                    (from search in ctx.Search
                     where search.Type == SearchType.Search &&
                     search.Query == "#vexpro"
                     select search)
                    .ToList();

                var rnd   = new Random();
                var tweet = searchResponse[rnd.Next(searchResponse.Count)];

                if (tweet != null)
                {
                    response.Result = new Twitter
                    {
                        status = tweet.Statuses.ToString()
                    };
                    return(response);
                }
                ;
            }
            catch (Exception)
            {
                response.Add("Ocorreu um problema ");
                return(response);
            }
            return(response);
        }