Twitter Hello-World: that was easy
I'm working on Twitter integration for Tipjoy. It's going to be all about pushing your favorite content out to your friends on twitter, like our FriendFeed integration.
I just finished a 'hello world' integration. Here is the result.
Here is the code:
#!/usr/bin/python
import urllib
import urllib2
import urlparse
username = "tipjoy"
password = "get.your.own"
realm = "Twitter API"
url = 'http://twitter.com/statuses/update.json'
(scheme, netloc, path, params, query, fragment) = urlparse.urlparse(url)
handler = urllib2.HTTPBasicAuthHandler()
handler.add_password(realm, netloc, username, password)
opener = urllib2.build_opener(handler)
text = "hello from python"
data = {'status': text}
encoded_data = urllib.urlencode(dict([(k, unicode(v).encode('utf-8')) for k, v in data.items()]))
url_data = opener.open(url, encoded_data).read()