Published on Sake.in.th (https://sake.in.th)

หน้าแรก > หน้าหลัก > เขียน tweet app อย่างง่าย

เขียน tweet app อย่างง่าย [1]

เขียนโดย sake [2] เมื่อ 2010-02-23 17:18


Twitter มี API ที่ใช้งานง่ายที่หนึ่ง ตัวอย่างคือใช้ python ซึ่งทำให้ง่ายไปอีก
เริ่มจาก โหลด API http://code.google.com/p/python-twitter/ [3]
ในกรณีนี้ผมใช้ผ่าน mercurial
จากนั้น install

  1. hg clone https://python-twitter.googlecode.com/hg/ [4] python-twitter
  2. cd python-twitter/
  3. sudo python setup.py install

จากนั้น เริ่มเขียนครับ

  1. sake@sake [5]-laptop:~/project/python-twitter/examples$ python
  2. Python 2.6.4+ (r264:75706, Jan 31 2010, 22:10:28)
  3. [GCC 4.4.3] on linux2
  4. Type "help", "copyright", "credits" or "license" for more information.
  5. >>> import twitter
  6. >>> api = twitter.Api()
  7. >>> api = twitter.Api(username="myusername",password="mypassword")
  8. >>> api.PostUpdate(u'ทดสอบโพสภาษาไทย โดยใช้ python-twitter')

กรณีจะดึงข้อมูลก็ง่ายดาย

  1. >>> import twitter
  2. >>> api = twitter.Api()
  3. >>> api = twitter.Api(username="myusername",password="mypassword")
  4. >>> statuses = api.GetPublicTimeline()
  5. >>> print [s.user.name for s in statuses]
Tags: 
programming [6]
Python [7]
Twitter [8]

Source URL (modified on 2012-12-17 23:37): https://sake.in.th/node/90

Links
[1] https://sake.in.th/blog/%E0%B9%80%E0%B8%82%E0%B8%B5%E0%B8%A2%E0%B8%99-tweet-app-%E0%B8%AD%E0%B8%A2%E0%B9%88%E0%B8%B2%E0%B8%87%E0%B8%87%E0%B9%88%E0%B8%B2%E0%B8%A2
[2] https://sake.in.th/users/sake
[3] http://code.google.com/p/python-twitter/
[4] https://python-twitter.googlecode.com/hg/
[5] mailto:sake@sake
[6] https://sake.in.th/tags/sitetags/programming
[7] https://sake.in.th/category/sitetags/python
[8] https://sake.in.th/tags/sitetags/twitter