public async Task TestConnector() { IDataConnector Connector = DataConnectorFactory.CreateDataConnector("twitter"); Assert.IsNotNull(Connector); Assert.IsInstanceOfType(Connector, typeof(IDataConnector), $"{nameof(Connector)} must inherit {nameof(IDataConnector)}"); Assert.IsInstanceOfType(Connector, typeof(BaseComponents.DataConnector), $"{nameof(Connector)} must inherit {nameof(BaseComponents.DataConnector)}"); Assert.IsInstanceOfType(Connector, typeof(TwitterConnector), $"{nameof(Connector)} must be a {nameof(Connectors.TwitterConnector)}"); TwitterConnector TwitterConnector = (TwitterConnector)Connector; Assert.IsNotNull(TwitterConnector.ProviderName, $"{nameof(TwitterConnector)} must have a value (\"Twitter\") assigned."); Assert.AreEqual("Twitter", TwitterConnector.ProviderName, $"{nameof(TwitterConnector.ProviderName)} is not the expected value (\"Twitter\")."); int DataCount = await TwitterConnector.RetrieveData("#felixbaumgartner"); Assert.IsTrue(DataCount > 0, $"{nameof(DataCount)} must have a value greater than 0. If the value is 0, it means no search results where returned."); }
public MainWindowViewModel() { Connector = new TwitterConnector(this); }
private void FireUpTheWork() { //TODO: No exception handling so far. Handle it better. //TODO: Don't block as much as possible and don't use Result var globalStreamGroupName = "Global"; CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); State["cts"] = cancellationTokenSource; var isCycleOn = true; using (TwitterConnector twitterConnector = new TwitterConnector()) { //TODO: Response message might be other than 200 // if this is the case, the other parts of the code might not work // as excpected. Handle this. var response = twitterConnector.GetLocationBasedConnection("-165.0,-75.0,165.0,75.0").Result; //var response = twitterConnector.GetSampleFirehoseConnection().Result; var contentResult = response.Content.ReadAsStreamAsync().Result; using (var streamReader = new StreamReader(contentResult, Encoding.UTF8)) { var clients = GlobalHost.ConnectionManager.GetHubContext <TwitterHub>().Clients; var cts = (CancellationTokenSource)State["cts"]; while (!streamReader.EndOfStream && !cts.IsCancellationRequested) { var result = streamReader.ReadLine(); if (!string.IsNullOrEmpty(result)) { //TODO: Handle the exceptions here. var tweetJToken = JsonConvert.DeserializeObject <dynamic>(result); var tweetObj = tweetJToken["text"]; if (tweetObj != null) { var tweetText = tweetObj.ToString(); var userScreenName = tweetJToken["user"]["screen_name"].ToString(); var imageUrl = tweetJToken["user"]["profile_image_url_https"].ToString(); var tweet = new TweetMapR.Entities.Model.Tweet() { TweetText = tweetText, User = userScreenName, ImageUrl = imageUrl }; var coordinatesRoot = tweetJToken["coordinates"]; if (coordinatesRoot != null && !string.IsNullOrEmpty(coordinatesRoot.ToString())) { var coordinates = coordinatesRoot["coordinates"]; tweet.Longitude = coordinates[0]; tweet.Latitude = coordinates[1]; } //broadcast tweet to global stream subscribers clients.Group(globalStreamGroupName).broadcastTweet(tweet); } } } if (cts.IsCancellationRequested) { isCycleOn = false; } } } if (isCycleOn) { FireUpTheWork(); } }
public UserManagement(TwitterConnector connector) { _connector = connector; }
static void Main(string[] args) { //リクエストトークン取得==================================================================== //ApiTestNoCallback //callbackurl設定なしアカウント const string CONSUMER_KEY = "************************************"; const string CONSUMER_SECRET = "***************************************"; Auth auth = new Auth(CONSUMER_KEY, CONSUMER_SECRET); // リクエストトークンを取得する auth.GetRequestToken(); //ユーザーにRequestTokenを認証してもらう Console.WriteLine("Please jump to the AuthenticationURL:"); Console.WriteLine("https://api.twitter.com/oauth/authorize?oauth_token=" + auth.RequestToken); Console.Write("Enter your PIN:"); string pin = Console.ReadLine(); // アクセストークンを取得する auth.GetAccessToken(pin); // 結果を表示する Console.WriteLine("Your AccessToken: " + auth.AccessToken); Console.WriteLine("Your AccessTokenSecret: " + auth.AccessTokenSecret); Console.WriteLine("Your UserId: " + auth.UserId); Console.WriteLine("Your ScreenName: " + auth.ScreenName); //===================================================================================== //==================================================== //debug Console.WriteLine("debug start! Enter return key!"); Console.ReadKey(); Console.Write("<===== This is a tiny Twitter client on console =====>\n"); TwitterConnector tc = new TwitterConnector( auth.ConsumerKey, auth.ConsumerSecret, auth.AccessToken, auth.AccessTokenSecret, auth.UserId, auth.ScreenName); Console.WriteLine("Enter some screen name you want to get its Tweets"); Console.WriteLine("e.g)@:muji_net"); Console.Write("@:"); string sn = Console.ReadLine(); tc.GetUsrTimeline(sn); Console.WriteLine("====================================================================="); Console.WriteLine("Completed getting his Tweets!"); Console.WriteLine("Enter return key!\n"); Console.ReadKey(); Console.WriteLine("Please enter return key to start to get your home timeline"); Console.ReadKey(); tc.GetHomeTimeline(); Console.WriteLine("====================================================================="); Console.WriteLine("Completed getting your home timeline!"); Console.WriteLine("Enter return key!\n"); Console.ReadKey(); Console.WriteLine("Enter some tweet id you want to get"); Console.WriteLine("e.g)id:669840927989456896"); Console.Write("tweet id:"); string id = Console.ReadLine(); tc.GetTweet(long.Parse(id)); Console.WriteLine("====================================================================="); Console.WriteLine("Completed getting tweet from tweet id!"); Console.WriteLine("Enter return key!\n"); Console.ReadKey(); Console.WriteLine("Please enter return key to start to get your mentions timeline"); Console.ReadKey(); tc.GetMentionsTimeline(); Console.WriteLine("====================================================================="); Console.WriteLine("Completed getting your mentions timeline!"); Console.WriteLine("Enter return key!\n"); Console.ReadKey(); Console.WriteLine("Please enter some text to post. (Caution!: This text will post your time line!)"); Console.Write("text:"); string text = Console.ReadLine(); tc.Update(text); Console.WriteLine("====================================================================="); Console.WriteLine("Completed posting!"); Console.WriteLine("Enter return key!\n"); Console.ReadKey(); //debug Console.WriteLine("debug end! Enter return key!"); Console.ReadKey(); //===================================================== }
public TweetManagement(TwitterConnector connector) { _connector = connector; }