Can't get streaming to work

Jun 10, 2012 at 1:24 AM

Hi.

 

Loving the library, and it is rather simple to use, except I am being tripped up by one small thing.
I'm trying to get streaming (public stream with a track) to work, but I can't find any examples, and the code I have below just does nothing. If I watch in Fiddler nothing happens when this is called:

var twitterCtx = new TwitterContext(auth);
          //  twitterCtx.StreamingUserName = "test";
          //  twitterCtx.StreamingPassword = "test";
            var searchResponse1 = 
                (from tweet in twitterCtx.Streaming
                 where tweet.Type == StreamingType.Filter &&
                       tweet.Track == "hi"
                 select tweet)
                .StreamingCallback(strm =>
                    {
                        TweetResults.Add(new Tweet { Text = strm.Content });
                    }).SingleOrDefault();

My auth is definitely working, as doing things like saving a search work fine. And doing a normal search gives results.

 

So what am I doing wrong? And is it possible to use OAuth with streaming because accessing the users username and password is impossible in my case (I did still try putting UN/Pass, but it didnt work either)?

 

Thanks!

Coordinator
Jun 10, 2012 at 3:12 AM

Hi,

I noticed that you're using Filter Stream.  This requires a UserName and Password, but not OAuth.  You might see the username/password streams switch over to OAuth some time in the future - some are OAuth and others are username/password.  You might want to create a special Twitter account, just for your application and use those credentials.

I have a sample in the downloadable code, via the Source tab, in the LinqToTwitterDemos project in the StreamingDemos.cs file.  I just tried it with username & password and the same track, "hi", and was able to get a response. 

The responses will arrive through StreamingCallback, and *not* searchResponse1.

If you've been trying different things, one after the other and they've been failing, you might want to wait a while and just try with username/password. 

On the Fiddler2 Toolbar, there's a Stream button that you should toggle on.  If you run Fiddler2 without turning on the Stream, you won't receive results.  Otherwise, try it with the username/password and Fiddler2 turned off.

Joe

Jun 10, 2012 at 11:29 PM
Edited Jun 10, 2012 at 11:33 PM

Thanks for the quick answer!

That demo does in-fact work, and caused me to repeatedly bang my head against the wall because the code was identical to mine. Eventually I did what I should have done in the first place and just tried out the source.

I found a bug on line 669 of LinqToTwitter.TwitterExecute.

 

req.Headers[HttpRequestHeader.UserAgent] = UserAgent;

 

With the new WinRT API's, HttpWebRequest has been culled a bit, and you can no longer set the user agent on it. The solution would be to use something like HttpClient. I'm a bit too short on time to do that adjustment (I'm not even sure that HttpClient will provide the needed methods to work with Streaming), so the short term fix would be to simple comment out that line. I looked around the twitter dev portal, and found that for the search methods a unique UserAgent is required, but can't find a similar requirement for the streams.

Thanks for the help

 

EDIT: Just another question while on the topic - you say that I should create an account for my app and use those credentials. What happens if my app goes to store, someone uses fiddler etc to sniff the traffic and finds out the credentials? They could change the password on the site and kill my app?

Coordinator
Jun 11, 2012 at 5:39 AM

I'll have to take a look at the WinRT library - I just started with that and am tracking down all the glitches.  Thanks for the research on UserAgent.  I commented those lines out and verified that the Console app still works, but will have to look closer at the WinRT.

On the username/password issue - all the LINQ to Twitter URLs default to https. 

Joe