Aim: a school we work with wants to see photos and text from the last e.g. 4 tweets, to be displayed on a large screen in the entrance foyer. I'd like to do this using Node-RED because it's familiar to me, and I like the options for integrating other info on the display screen at a later date (weather / news snippets etc.)
QUESTION 1 -Has anyone done such a project?
Unfortunately the Twitter node only seems to pick up on tweets that have been published after the nodes are in place, as opposed to being able to periodically poll for the last 4 tweets. I guess this is because it uses the stream API.
QUESTION 2 - is there any way to pick up the most recent x tweets from a search query?
Having played around with this a bit today, I've been able to extract the image URL .tweet.entities.media.media_url and would obviously be possible to extract multiple images by looking at the array found under "extended_entities), i.e. tweet.extended_entities.media.media_url
Quick view of the work involved:
twitter node uses streaming API, which means it doesn't search last x tweets, but rather collects tweets as they come in.
we should therefore consider storing tweets and images in the database, so that if for some reason we become disconnected, or we do redeploy and the stream is lost, we don't have a blank display
we need to determine whether there is an image, and display different elements onto dash accordingly. i.e. large text if there is no image, smaller text if it accompanies one or more images
we also need to determine how many images there are and size them smaller, to fit into the same space as a single-image tweet
we need to determine the size of images and resize them according to their longest size, in order that there are no image truncations with scroll bars within dashboard elements
Let me know if anyone has done something like this!
The twitter node we have uses streaming so that's a start.
I did build a wordcloud driven by tweets once upon a time, that was used as a screensaver in a lab. Worked quite nice as the key word was automatically the largest word in the cloud it showed what was going on "around" that topic. It refreshed whenever new messages arrived and got added to the counts (and removed so it never got too big).
Actually I think I made a node for it somewhere but never published it.
So my solution so far is to get the multiple tweet attachments, download them and store to disk using the filename created by twitter for the sake of ease, and then store the display text and an array of filenames in a global context object. Pretty much done that now, and next I plan to grapple with the dashboard to update directly from the local "cache" of tweets.
Seems better that way, at least we can reliably have x number of tweets displayed at any time. (On the basis of the fact that x number have been tweeted since the flow was installed...)
Will post back my solution here when it's finished.
If you pick an oauth 2 contrib node you can interact quite easily with the twitter API. The rate limiting is so high you won’t have to worry about that for your project. Last Christmas I wrote a blog post where I referenced the twitter API docs, calling them a sight for sore eyes. I still think that. They’re complete, easy to use and incredible well explained. Might take some getting used to the format, but most of all both the API itself as well as the API docs are very consistent.
@TotallyInformation is correct though, that’s exactly the endpoint you need. And by setting the since_id you can restrict it in getting results you haven’t seen yet. Merge that with what you keep stored. Then you can filter that results array to only keep the latest N tweets.