Skip to content

Instantly share code, notes, and snippets.

@icebeam7
Created April 12, 2018 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icebeam7/a33d7a39ed6bb7f375b58002dd71a80c to your computer and use it in GitHub Desktop.
Save icebeam7/a33d7a39ed6bb7f375b58002dd71a80c to your computer and use it in GitHub Desktop.
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