Gelder Gelder - 4 months ago 21
JSON Question

TweetInvi Tweets to string or Json

I'm certainly not well experienced when it comes to c# but require it odd time SSIS, I'm trying to use TweetInvi to extract a timeline and then insert that time line data into a string file into a database to be processed. but I'm struggling...please help or point me in a direction of help.

here is what I've got

private void button1_Click(object sender, EventArgs e)
{
Auth.SetApplicationOnlyCredentials("XxxxxxxxXXXxxxXXX", "XXxxxXXX");

MessageBox.Show("started");

var usertimelinetweets = Timeline.GetUserTimeline("Testr",1);



this.Close();


Clearly at the most basic point, but I simple am in the dark here.

Answer

What you are trying to achieve is actually quite simple. Tweetinvi is automatically installed with Newtonsoft.Json.NET.

You can use Tweetinvi 1.0 support for serialization as followed :

var tweets = Timeline.GetHomeTimeline();

// Store 1 array
var json = JsonConvert.SerializeObject(tweets.Select(x => x.TweetDTO));

// Or iterate
foreach (var tweet in tweets)
{
    var tweetjson = JsonConvert.SerializeObject(tweet.TweetDTO);
}

You can learn more in the documentation: https://github.com/linvi/tweetinvi/wiki/Serialization-and-Deserialization

Note that for some reason Timeline.GetUserTimeline requires User Authentication as noted in the documentation : https://dev.twitter.com/rest/reference/get/statuses/user_timeline.

To do that use Auth.SetUserCredentials as opposed to Auth.SetApplicationOnlyCredentials.