Script Script Simple Streaming API

I would like to create a page that displays the last tweet using a special hash tag.

I currently have one working one, but it uses the search API. The problem is that it is not real-time, so I would like to move it to the Streaming API .

I've seen online examples, but they all seem to have databases and stuff. I didn’t want that. Just something really simple.

Can someone guide me on the right path or even better, show me an example?

Thanks.

+4
source share
3 answers

Well, the streaming API requires you to maintain a connection. This requires a server process with an infinite loop to get the latest tweets.

Assuming this is possible for you (doubt it almost never works on regular web hosts), and you want to do it without a database, you still have to get the data from this backend script into your front-end scripts. Perhaps you can use a .txt file for this.

You always need a backend to use the streaming API. It cannot (should not) be used in a regular PHP script.

+1
source

Try this. Please read the documentation (very easy to understand). This is database related, but hardly anything you need for the code. It is really very simple!

Scripting language used: PHP

Library Used: Phirehose

+1
source

Well, the simplest solution I can think of is AJAX. You will need a CGI script (or program) that retrieves data from the Twitter Streaming API . In the methods you will find statuses/filter , which will return an array of statuses for your keywords.

Draw a conclusion from the CGI script, parse it and put the information in an array in Javascript. When a new status appears, release the last one. Check your CGI script constantly to get new statuses, process their processing and put them on the page.

I don’t think anyone will write such specific code unless you offer generous generosity as @rdlowry said in his comment. :)

However , I recommend you write it yourself. He will teach you how to solve similar problems, how to approach such problems and how to read API documentation (which is also very important).

All the best.

-1
source

Source: https://habr.com/ru/post/1385333/


All Articles