Streaming API

Jul 7, 2014 at 5:13 PM
I cant get the streaming API to work correctly.

I have read the discussion https://tweetinvi.codeplex.com/discussions/461350, and downloaded the sample https://tweetinvi.codeplex.com/releases/view/119124.

As a quick side note, the Sample seams to not work (for me) either, I get a null reference error when trying to get a user by ID (not the main issue, this works on my project), and if I add a track of "the" (a keyword I thought would be pretty common), I get no results when I click "Start Stream".

So my issue. I've used your sample Stream code on the Documentation page, and it just doesn't do anything, except lock my program. I removed the AddTrack and added the AddFollow I was trying to add before (my own account), so I could trigger the event by sending a tweet. Again, it just does nothing.

What am I missing? I'm not sure what information you need to help me, so whatever you need, ask.

Thanks
Jul 7, 2014 at 6:43 PM
Edited Jul 7, 2014 at 6:43 PM
Hi,
peelypeel.


Why wont you try some simple code such as:
TwitterCredentials.SetCredentials("2593627711-oaxE3OHkkn54Vn2XDF7dVnU84Mks24hEMkj2...", "l8rYxbC7ctbdu3sW30MZWW5UyKTHLIw5RTtxsIW36A...",
                                                  "B20EvnMAlJFvzwf5RjhpFZ...", "xBL9J3uGUnIPnZuyzblAw358warmuW1Hrv7qEHpOSrruf09...");
var tweet = Tweet.PublishTweet("TWEET SMTH");
Of couse you need proper tokkens and so on... And what have you tried so far?

Kind regards,
Insaf.
Coordinator
Jul 8, 2014 at 12:37 AM
Hello here,

The fact that your program freezes is normal. When you use the Stream api you need to invoke it in a specific thread.
var stream = Stream.CreateFilteredStream();
stream.MatchingTweetReceived += (sender, args) =>
{
    var tweet = args.Tweet;
    Console.WriteLine(tweet.Text);
};
var thread = new Thread(() => stream.StartStreamMatchingAllConditions());
thread.Start();
Of course, you will need to set your credentials as explained by Insafq.

Please let me know if this is of any help.
Regards,
Linvi
Jul 8, 2014 at 10:39 AM
Edited Jul 8, 2014 at 10:41 AM
Insafq wrote:
Hi,
peelypeel.

Why wont you try some simple code such as:
var tweet = Tweet.PublishTweet("TWEET SMTH");
Of couse you need proper tokkens and so on... And what have you tried so far?
Kind regards,
Insaf.
Thanks for the reply, but that wasn't really the main issue.

linvi wrote:
Hello here,

The fact that your program freezes is normal. When you use the Stream api you need to invoke it in a specific thread.

Please let me know if this is of any help.
Regards,
Linvi
Thank you Linvi, after a bit of play, that worked. It seams if I add a AddFollow after an AddTrack, both arguments are completely ignored, but if i have just an AddFollow, or just an AddTrack, it works. This isn't an issue for me right now, but wondered if that was meant to happen?

Thanks for the help

Crafty Edit:
P.s. I've read the Streaming API, and all the parts about disconnects, backing off and 420 codes etc. Does Tweetinvi deal with this, or will I need to write that myself?
Coordinator
Jul 9, 2014 at 7:25 PM
Hi,

Thank you Linvi, after a bit of play, that worked. It seams if I add a AddFollow after an AddTrack, both arguments are completely ignored, but if i have just an AddFollow, or just an AddTrack, it works. This isn't an issue for me right now, but wondered if that was meant to happen?

Well you need to understand how the Twitter API work. When you add a track or add a follower, Twitter will send all the tweets that match either the track OR the follower.

Please read the following discussion to understand how Tweetinvi manages it https://tweetinvi.codeplex.com/discussions/539444.

Tweetinvi provide you information about which keyword have been matched.
stream.MatchingTweetReceived += (sender, args) =>
{
    var matchingTracks = args.MatchingTracks;
};
Please note:
// Get either Hello or Plop
AddTrack("Hello");
AddTrack("Plop");

// Get both Hello and plop
AddTrack("Hello Plop");
I have never received a Tweet that was not matching the tracks so please be careful when analyzing what you receive.
Let me know if you find anything.
Linvi