Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Sentimental Tweets: ServicioTwitter.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using LinqToTwitter;
using SentimentalTweets.Modelos;
using SentimentalTweets.Helpers;
namespace SentimentalTweets.Servicios
public static class ServicioTwitter
private static async Task<IAuthorizer> AutorizarTwitter()
var auth = new ApplicationOnlyAuthorizer()
CredentialStore = new InMemoryCredentialStore
ConsumerKey = Constantes.TwitterApiKey,
ConsumerSecret = Constantes.TwitterApiSecret,
await auth.AuthorizeAsync();
return auth;
public static async Task<List<Tweet>> ObtenerTweets(string dato)
var twitter = new TwitterContext(await AutorizarTwitter());
var tweets = new List<Tweet>();
var busqueda = await (from t in twitter.Search
where t.Type == SearchType.Search &&
t.Query == dato
select t).SingleOrDefaultAsync();
if (busqueda != null && busqueda.Statuses != null)
busqueda.Statuses.ForEach(tweet =>
tweets.Add(new Tweet()
Mensaje = tweet.Text,
Idioma = tweet.Lang
return tweets;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.