Python: Twitter
Revision as of 07:57, 3 December 2015 by Onnowpurbo (talk | contribs)
Sumber: https://code.google.com/p/python-twitter/
Instal Dependency dan Python Twitter
Lakukan
cd /usr/local/src wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py python ez_setup.py --insecure easy_install simplejson easy_install httplib2-master.zip easy_install python-oauth2-master.zip easy_install python-twitter-1.1.tar.gz
Test API Twitter
Code
import twitter api = twitter.Api(consumer_key='consumer_key', consumer_secret='consumer_secret', access_token_key='access_token', access_token_secret='access_token_secret') print api.VerifyCredentials()
Akan keluar informasi panjang sekali, misalnya
{"id": 16133, "location": "Philadelphia", "name": "bear"}
Print Public TimeLine
statuses = api.GetTimeline() print [s.user.name for s in statuses] [u'DeWitt', u'Kesuke Miyagi', u'ev', u'Buzz Andersen', u'Biz Stone']
Print / fetch single "user" public message
statuses = api.GetUserTimeline('onnowpurbo') print [s.text for s in statuses]
Print / fetch user friends
users = api.GetFriends() print [u.name for u in users]
Post a Twitter status message
status = api.PostUpdate('I love python-twitter!') print status.text
I love python-twitter!
Ada banyak API method, baca
$ pydoc twitter.Api $ pydoc twitter.Status $ pydoc twitter.User $ pydoc twitter.DirectMessage