using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using Tweetinvi;
using Tweetinvi.Core.Enum;
using Tweetinvi.Core.Extensions;
using Tweetinvi.Core.Interfaces;
using Tweetinvi.Core.Interfaces.Controllers;
using Tweetinvi.Core.Interfaces.DTO;
using Tweetinvi.Core.Interfaces.DTO.QueryDTO;
using Tweetinvi.Core.Interfaces.Models;
using Tweetinvi.Core.Interfaces.Models.Parameters;
using Tweetinvi.Core.Interfaces.oAuth;
using Tweetinvi.Core.Interfaces.Streaminvi;
using Tweetinvi.Json;
using Stream = Tweetinvi.Stream;
using System.Configuration;
using System.Runtime.InteropServices;
using System.Net.NetworkInformation;
namespace Twitter_Scanner
{
class Program
{
static void Main(string[] args)
{
TwitterCredentials.SetCredentials(ConfigurationManager.AppSettings["token_AccessToken"], ConfigurationManager.AppSettings["token_AccessTokenSecret"], ConfigurationManager.AppSettings["token_ConsumerKey"], ConfigurationManager.AppSettings["token_ConsumerSecret"]);
var loggedUser = User.GetLoggedUser();
var settings = loggedUser.GetAccountSettings();
Console.WriteLine(settings.ScreenName + ": You Are Successfully Connected to Twitter API");
GetCredentialsRateLimits();
Console.WriteLine("Twitter Newswire Scanner");
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("News Sources: ");
foreach (var NewsSource in File.ReadLines(ConfigurationManager.AppSettings["Path_To_NewsSource_Text_File"]))
{
Console.Write(NewsSource.ToString() + " ");
}
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("Keywords: ");
foreach (var KeyWords in File.ReadLines(ConfigurationManager.AppSettings["Path_To_KeyWords_Text_File"]))
{
Console.Write(KeyWords.ToString() + " ");
}
Console.WriteLine();
Console.WriteLine();
streamThread();
Console.Read();
}
// >>>>>>>>>>>>>>>>>>>>>CUSTOM SEARCH FILTERING<<<<<<<<<<<<<<<<<<<//
private static void Stream_FilteredStreamExample()
{
try
{
var stream = Stream.CreateFilteredStream();
foreach (var KeyWords in File.ReadLines(ConfigurationManager.AppSettings["Path_To_KeyWords_Text_File"]))// Gets Key Words From Text File
{
stream.AddTrack(KeyWords);
}
stream.MatchingTweetAndLocationReceived += (sender, args) =>
{
var tweet = args.Tweet;
foreach (var NewsSource in File.ReadLines(ConfigurationManager.AppSettings["Path_To_NewsSource_Text_File"]))// Filter by News Sources in Text File
{
if (tweet.Creator.ScreenName == NewsSource)
{
Console.WriteLine(tweet.Creator.ScreenName + " :-->> " + tweet.Text);
System.Media.SoundPlayer player = new System.Media.SoundPlayer(ConfigurationManager.AppSettings["Path_To_Sound_Alert"]);
player.Play();
}
else
{
//do nothing
}
}
};
stream.StartStreamMatchingAllConditions();
}
catch
{
Console.WriteLine("Stream Terminated");
}
}
private static void GetCredentialsRateLimits()
{
var credentials = TwitterCredentials.CreateCredentials(ConfigurationManager.AppSettings["token_AccessToken"], ConfigurationManager.AppSettings["token_AccessTokenSecret"], ConfigurationManager.AppSettings["token_ConsumerKey"], ConfigurationManager.AppSettings["token_ConsumerSecret"]);
var tokenRateLimits = RateLimit.GetCredentialsRateLimits(credentials);
Console.WriteLine("Remaning Requests for GetRate : {0}", tokenRateLimits.ApplicationRateLimitStatusLimit.Remaining);
Console.WriteLine("Total Requests Allowed for GetRate : {0}", tokenRateLimits.ApplicationRateLimitStatusLimit.Limit);
Console.WriteLine("GetRate limits will reset at : {0} local time", tokenRateLimits.ApplicationRateLimitStatusLimit.ResetDateTime.ToLongTimeString());
}
private static void Exceptions_GetExceptionsInfo()
{
TwitterCredentials.Credentials = null;
var user = User.GetLoggedUser();
if (user == null)
{
var lastException = ExceptionHandler.GetLastException();
Console.WriteLine(lastException.TwitterDescription);
}
}
private static void streamThread()
{
var t = new Thread(() =>
{
Console.WriteLine("Stream Thread Started...");
Stream_FilteredStreamExample();
});
t.Start();
Console.WriteLine(t.ThreadState.ToString()+" Running");
}
}
}
Having an issue getting tweets via the filtered stream, contacted you, don't know if you got a chance to look at it.Everything works fine until I try to filter by screen name, if I comment out that code, tweets come streaming in based on keywords detected in those tweets.
There are no errors thrown, all the text files and config are in the correct place. Everything connects fine, and returns my username once it connects to the api.
But once I filter the tweets by screen name, nothing comes through, which is strange because prior to last week everything was working fine.
Thanks for any help you can give me.