Streams & VB.NET

Oct 9, 2013 at 4:17 PM
Edited Oct 9, 2013 at 4:19 PM
Joe, you must get a ton of newbie questions like this but please bear with me. I'm a new programmer and I'm translating your C# examples to VB as I go too. I am able to authenticate and send a status update/DM. I'd now like to start using a UserStream to see received DMs and tweets. I'm using a console application. I can see calls (using fiddler) to for my verify_credentials request and my direct_message request. But when I execute the following code I see no request to to set up the stream. I'm assuming I should see something in order to establish the stream right?

Code (tctx is my twitter context):
Dim result = (From strm In tctx.UserStream Where strm.Type = UserStreamType.User _
                Select strm).StreamingCallback(
                  If (strm.Status = TwitterErrorStatus.RequestProcessingException) Then
                  End If
                         Log.Debug("Result of stream: " & strm.Content)
                 End Sub)
I also tried the JSON parser you recommend in the docs - there's not much in the way of examples, but I created a parser and then added two event handlers:
parser = tctx.UserStream.Where(Function(us) us.Type = UserStreamType.User).CreateParser()
Public Sub foo(sender As Object, e As UserStreamReceivedStatusEventArgs) Handles parser.ReceivedStatus
        Log.Debug("Status: " & e.Json.ToString)
End Sub
Public Sub bar(sender As Object, e As UserStreamReceivedFriendsEventArgs) Handles parser.ReceivedFriends
        Log.Debug("Friends: " & e.Json.ToString)
End Sub
The 'bar' sub gets called an I get a list of my friends (as per the twitter API) but when I send a status update from a friends account, I expect 'foo' to get called but I get the below exception, which I don't understand.
An unhandled exception of type 'System.MissingMethodException' occurred in LinqToTwitter.dll

Additional information: Method not found: 'LinqToTwitter.Status LinqToTwitter.Status.CreateStatus(System.Xml.Linq.XElement)'.
Could you shed some light for me please?

Oct 9, 2013 at 6:52 PM
Hi Gavin,

It looks like that parser hasn't been updated. I can tell by the call to CreateStatus(XElement) in the stack trace. There was a time when LINQ to Twitter consumed XML from Twitter, but they don't support XML anymore - only JSON.

I'll eventually need to add a stream parser to LINQ to Twitter. Here's a list of the message formats that are supported by streams:

Oct 9, 2013 at 8:16 PM
Edited Oct 9, 2013 at 8:18 PM
Thanks for the quick comeback Joe. So assuming I drop the suggested parser due to the XML vs JSON issue and use the code above with the lambda code. From the link you include a user stream does not include friend status updates only DMs and the other message types, is that correct?

If so, what's the recommended way of getting a stream of friend status updates? I assume polling the REST API every so often is one, but inefficient give rate limits and the fact that there will be a time delay equivalent to the poll interval.

I figured the first code snippet (as close as I could get to a VB translation of your demo C# code) would do the trick. Where am I going wrong?