/ Published in: Python

A way to post to twitter from Google AppEngine using urlfetch.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
class SendChime(webapp.RequestHandler): def get(self): self.response.headers['Content-Type'] = 'text/plain' username = self.request.get("username") login = username password = "password" chime = self.get_chime() payload= {'status' : chime, 'source' : "innertwitter"} payload= urllib.urlencode(payload) base64string = base64.encodestring('%s:%s' % (login, password))[:-1] headers = {'Authorization': "Basic %s" % base64string} url = "http://twitter.com/statuses/update.xml" result = urlfetch.fetch(url, payload=payload, method=urlfetch.POST, headers=headers) self.response.out.write(result.content) def get_chime(self): now = datetime.datetime.now() chime = "........*chime*.............." + now.ctime() return chime def main(): application = webapp.WSGIApplication( [('/innertwitter', InnerTwitter), ('/sendchime', SendChime)], debug=True)
URL: http://highscalability.com/using-google-appengine-little-micro-scalability
Comments
