Some of the information here may be outdated, please check the book instead
[edit]

post a twit

def post_twit(username,password,message):
  import urllib, urlib2, base64
  import gluon.contrib.simplejson as sj
  args= urllib.urlencode([('status',message)])
  headers={}
  headers['Authorization'] = 'Basic '+base64.b64encode(username+':'+password)
  request = urllib2.Request('http://twitter.com/statuses/update.json', args, headers)
  return  sj.loads(urllib2.urlopen(req).read())

get twits

def get_twits():
  user='web2py'
  import gluon.tools
  import gluon.contrib.simplejson as sj
  page = gluon.tools.fetch('http://twitter.com/%s?format=json' % user)
  tweets=XML(sj.loads(page)['#timeline'])
  return dict(tweets=tweets)

No third party libraries required. Just old plain web2py.

© 2008-2010 by Massimo Di Pierro - All rights reserved - Powered by web2py - design derived from a theme by the earlybird
The content of this book is released under the Artistic License 2.0 - Modified content cannot be reproduced.