From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Twitter Toolkit for LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Support for Streaming API?

Hey guys, I was curious if I missed support for the Twitter Streaming API? It looks like the i3 Twitter Toolkit only uses the REST API, but I could be mistaken. Otherwise, do you have any suggestions on how to use the Streaming API with LabVIEW? It seems like that's what we need to use Twitter for control.

The part I'm mainly stuck on is keeping the HTTP stream open.

Thanks!

Will
CLA, CLED, CTD, CPI
LabVIEW Champion
Choose Movement Consulting
choose-mc.com
0 Kudos
Message 1 of 5
(11,394 Views)

Hey Will_S!

Unfortunately it looks like the built-in HTTP VIs in LabVIEW cannot be used to efficiently implement the Twitter Streaming API. The problem is that the HTTP VIs themselves do not support streaming of the data that is received. Even though you can specify a timeout, you will not receive any data until the timeout occurs (and I am not sure if the HTTP VIs return the buffer at that time or discard the data as a timeout happened).

Result: Would have to specify a long timeout to buffer data from the stream which means updates would be slower. In addition, the reconnection process sets a limit on how short the timeout can be before you are banned.

An option that could have been viable would be manually implementing an HTTP/1.0 VI using the TCP functionality to enable the long poll and streaming. Unfortunately Twitter has deprecated the HTTP/1.0 support for the streaming API and while implementing HTTP/1.1 with the required features (chunked encoding, etc.) would not be unimaginable, it would be the manually implementation of required SSL support that would be a stick in the mud.

Result: At this time there are not really any pure LabVIEW ways to implement the streaming support (unless you can find a G HTTP/1.1 with SSL implementation to play with).

If you are on a desktop your best bet for using the streaming API would be to interface with a 3rd party Twitter .NET or C library but that can be a bit of a pain depending on the platforms you want to support and is not something I have tried. An approach could be to make or find an application that can forward the Twitter Streaming API info to a TCP socket that LabVIEW can then read from.

The best cross-platform pure LabVIEW solution at the moment is to query the streams at a rate that does not overflow the rate limits for the application. This is the approach used in the continuous functions (check <LabVIEW>\examples\LVH\i3 Twitter) such as Get New Tweets - Continuous, Search New Tweets - Continuous, etc. The Twitter Toolkit VIs used in the examples will only return new tweets that were not already returned to make control type applications easier.

For your control app if you are using the Get New Tweets Example, it calls the statuses/user_timeline endpoint which appears to be limited to 180 requests / 15 minute window at this time. With that you should be able to safely check for tweets every 5 seconds for the control system and each check can return up to 200 new tweets since the last request.

The best solution would be for Twitter to switch over to a websocket based approach and hopefully LabVIEW will have websockets well-supported before that happens (preferably as soon as possible ).

Let me know what you think and if you come up with a different approach!

Milan


Milan
0 Kudos
Message 2 of 5
(7,832 Views)

Hey Milan,

Thanks for the in-depth response! Unfortunately your response is what I was afraid of. I was hoping to use the Streaming API with an embedded target (cRIO or myRIO) so it could headlessly manage everything it needs.

I like your idea for the Get New Tweets Example. Checking for tweets every 5 seconds isn't too bad, but it's still the difference between "whoa, that's cool" and "ok, so it works if you need it." So depending on the final setup, it sounds like I might need to have a host application running on a desktop machine that calls a Python script or whatnot to get the data and then send that to the target. Let's get Twitter and NI focused on websockets 😄

Thanks again! I'll post back if I find a better solution.

Will
CLA, CLED, CTD, CPI
LabVIEW Champion
Choose Movement Consulting
choose-mc.com
0 Kudos
Message 3 of 5
(7,832 Views)

How to stream video from labview to HTML ? I mean i need to stream video from a USB webcam connected to myRIO to web browser via web sockets or web service ?

Is it possible ?

Please help !

0 Kudos
Message 4 of 5
(7,832 Views)

Hi rockyData,

This community group is for the Twitter Toolkit for LabVIEW. You may get a better response by asking in either the myRIO community page or the LabVIEW community page.

Best,

Milan


Milan
0 Kudos
Message 5 of 5
(7,832 Views)