Twitter API trick: use standard update method for direct messages

December 23, 2008 / Filed under: Twitter, API, Tips, Development

If you utilize the Twitter API, it may be refreshing to know that you can save some development time when working with direct messages.

The Twitter API provides various direct message methods, including one called "new", which sends a user a new direct message.

The URL for the new method looks like this:

http://twitter.com/direct_messages/new.<em>format</em>

This contrasts the standard "update" method URL, which looks like this:

http://twitter.com/statuses/update.<em>format</em>

Rather than building your application around those two separate, distinct URL's, you can choose to use only the "update" method, even for sending direct messages.

Just prepend the "update" method call's text with d username,, where username is the Twitter user to send the direct message to. Even though it's not an official direct message method, it still works. The magic occurs on Twitter's end, where the update is properly parsed to check for d username at the beginning.

This is a smart feature of the API, because they made it work just like the standard web interface works.

It's funny, though - I can't find any mention of this capability in the API documentation. Nothing should be assumed, especially something that saves developers time.

Comments/Mentions