Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can use the Twitter streaming API for direct messages. The first thing is you don't have to write it in PHP. Though you might be writing the site in PHP, that doesn't mean you have to use PHP for the background process of getting tweets.</p> <p>Firstly, you need some code that handles the data from the <a href="http://dev.twitter.com/pages/user_streams" rel="nofollow">User Streams API</a>. I'm not sure there is one for PHP, but <a href="http://code.google.com/p/phirehose/" rel="nofollow">phirehose</a> gets close. There's a patch available to get it to support User Streams.</p> <p>If you can't find a PHP library to support user streams, I'd suggest you consider using Ruby. It's pretty easy to write daemons in Ruby, and you can use a library like <a href="https://github.com/yayugu/twitterstream" rel="nofollow">twitterstream</a> which supports user streams.</p> <p>Then you need to write some code that basically processes the User Stream: checks to see if the thing you are getting is a direct message and puts it into the database. You probably also want to think about what you plan to do if this gets popular, and think about queues and database speed and so on. And if you are sending responses, you'll need to think about API rate limits and so on.</p> <p>Using the streaming API is very much like using the pull API: you get a blob of JSON with a whole set of key-value pairs. How do you decide which user you are handling? Well, you look at the user key and find their username.</p> <p>You'll also need to come up with a syntax for interacting with the site using DMs, and you'll want to create either a regular expression based parser, or perhaps use a lexer. You'll also want to test this pretty hard, using unit tests and so on. You are accepting text from a user: don't trust it!</p> <p>The streaming API isn't the only way to do it: you can also run a cron job and check the API for new messages. This is easier, but not nearly as good.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload