Posting to Twitter from Google AppEngine


/ Published in: Python
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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)

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.