Getting Json from twitter Stream

Mar 2, 2015 at 12:41 PM
Hi all!

I'm very new to programming and would really appreciate some help.

I'm having some problem in collecting the json from the Tweetinvi real-time stream.

These are my current code.

namespace TweetinviSTREAM
{
class Program
{
    static void Main(string[] args)
    {
        string Consumer = "removed";

        string ConsumerSecret = "removed";

        string AccessToken = "removed";

        string AccessTokenSecret = "removed";

        TwitterCredentials.SetCredentials(AccessToken, AccessTokenSecret, Consumer, ConsumerSecret);

        try
        {
            TwitterStream() ;
            Json_GetJsonForSavedSearchRequestExample();
        }
        catch (Exception e)
        {
            Console.WriteLine(e.ToString());
        }
        Console.ReadLine();
    }

    private static void TwitterStream()
    {
        var stream = Tweetinvi.Stream.CreateSampleStream();
        stream.TweetReceived += (sender, args) =>
        {
            Console.WriteLine(args.Tweet.Text);
        };

        stream.StartStream();
        Console.WriteLine("Stream State: " + stream.StreamState.ToString());
        }

    private static void Json_GetJsonForSavedSearchRequestExample()
    {
        var jsonResponse = SavedSearchJson.GetSavedSearches();
        Console.WriteLine(jsonResponse);
    }
    }
}
Mar 2, 2015 at 1:08 PM
I managed to solve it by referring to earlier threads about this.

var fstream = Stream.CreateFilteredStream();
fstream.AddTrack("hello");
fstream.JsonObjectReceived += (sender, args) =>
{
Console.WriteLine(args.Value);
};
fstream.StartStreamMatchingAllConditions();

Can anyone tell me how can I save the JSON file for later processing?
Coordinator
Mar 3, 2015 at 5:12 PM
Hi,

Could you be more precise in your question : Can anyone tell me how can I save the JSON file for later processing?
Because my answer would be 'in a database' but I don't think this is what you'd be expecting :p

Cheers,
Linvi
Mar 4, 2015 at 1:55 PM
I'm trying to save the JSON file locally but I'm having trouble coding it.

Can you direct me how pls?
Coordinator
Mar 6, 2015 at 4:49 PM
Well I would personally use a local database to store the data.
Then just insert the json with all the metadata you want.

After you will need to use the JsonObjectConverter to get back objects from your database.
When you are at this point of your application let me know and I will explain how to use this as this is "advanced" usage of Tweetinvi.

Cheers,
Linvi