Posted By

sgraber on 04/22/08


Tagged

python appengine


Versions (?)

Who likes this?

7 people have marked this snippet as a favorite

leighmac
taboularasa
frost_nomak
atr000
danielfilho
legacye
esfand


Posting to Twitter from Google AppEngine


 / Published in: Python
 

URL: http://highscalability.com/using-google-appengine-little-micro-scalability

A way to post to twitter from Google AppEngine using urlfetch.

  1. class SendChime(webapp.RequestHandler):
  2. def get(self):
  3. self.response.headers['Content-Type'] = 'text/plain'
  4. username = self.request.get("username")
  5.  
  6. login = username
  7. password = "password"
  8. chime = self.get_chime()
  9. payload= {'status' : chime, 'source' : "innertwitter"}
  10. payload= urllib.urlencode(payload)
  11.  
  12. base64string = base64.encodestring('%s:%s' % (login, password))[:-1]
  13. headers = {'Authorization': "Basic %s" % base64string}
  14.  
  15. url = "http://twitter.com/statuses/update.xml"
  16. result = urlfetch.fetch(url, payload=payload, method=urlfetch.POST, headers=headers)
  17.  
  18. self.response.out.write(result.content)
  19.  
  20. def get_chime(self):
  21. now = datetime.datetime.now()
  22. chime = "........*chime*.............." + now.ctime()
  23. return chime
  24.  
  25. def main():
  26. application = webapp.WSGIApplication(
  27. [('/innertwitter', InnerTwitter),
  28. ('/sendchime', SendChime)],
  29. debug=True)

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: erlichmen on November 17, 2010

Basic Auth is no longer supported on twitter, this snippet doesn't work.

You need to login to post a comment.